通过jQuery操作input标签下的单选框和复选框的基本属性
warning:
这篇文章距离上次修改已过201天,其中的内容可能已经有所变动。
在jQuery中,可以使用以下方法来操作input标签下的单选框(radio buttons)和复选框(checkboxes)的基本属性:
- 获取值:
// 获取单选框选中的值
var radioValue = $('input[name="radioName"]:checked').val();
// 获取复选框是否被选中
var checkboxIsChecked = $('#checkboxId').is(':checked');
- 设置值:
// 设置单选框为选中状态,其中'value'是你想要选中的值
$('input[name="radioName"][value="' + value + '"]').prop('checked', true);
// 设置复选框为选中状态
$('#checkboxId').prop('checked', true);
- 禁用输入:
// 禁用单选框
$('input[name="radioName"]').prop('disabled', true);
// 禁用复选框
$('#checkboxId').prop('disabled', true);
- 启用输入:
// 启用单选框
$('input[name="radioName"]').prop('disabled', false);
// 启用复选框
$('#checkboxId').prop('disabled', false);
这些方法可以帮助你通过jQuery操作单选框和复选框的基本属性。
评论已关闭