JQuery单选按钮Radio和复选框checkbox的操作代码
作者:梁云亮
这篇文章主要介绍了JQuery单选按钮Radio和复选框checkbox的操作,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
获取选中值:
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
$("input[id='rand_question']:checked").val();设置第一个Radio为选中值:
$('input:radio:first').attr('checked', 'checked');
$('input:radio:first').attr('checked', 'true');设置最后一个Radio为选中值:
$('input:radio:last').attr('checked', 'checked');
$('input:radio:last').attr('checked', 'true');根据索引值设置任意一个radio为选中值:
$('input:radio').eq(索引值).attr('checked', 'true'); //索引值=0,1,2....
$('input:radio').slice(1,2).attr('checked', 'true');根据Value值设置Radio为选中值
$("input:radio[value=payMethod'001']").attr('checked','true');
$("input[value=payMethod'001']").attr('checked','true');删除指定Value值的Radio
$("input:radio[value=payMethod001]").remove();删除第几个Radio
$("input:radio").eq(索引值).remove(); //索引值=0,1,2....
//删除第3个Radio:
$("input:radio").eq(2).remove();遍历Radio
let ids = [];
$('input:radio').each(function(index,domEle){
//写入代码
ids.push($(this).val());
});
ids = ids.join(',');到此这篇关于JQuery操作单选按钮Radio和复选框checkbox的文章就介绍到这了,更多相关JQuery操作单选按钮Radio内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
