各种input相关操作

来源:互联网 发布:恒生数据 编辑:程序博客网 时间:2024/06/06 00:32

1.radio

选择被选中的radio

$("input:radio:checked")

2.select

选中指定value的option

$('select[name=select1] [value=1]').attr("selected",true)
注意上面代码中有空格

3.checkbox

选中制定value的checkbox

$('input[name=invstyle][value="1"]').attr("checked","checked" );

被选中的个数

$("input[type=checkbox][name=invstyle][checked]").length

上面这种取个数的有时候不准,用下面这个

var arr_len = 0;$('input[name=invstyle]').each(function(){     if($(this).prop('checked') == true){           arr_len += 1;       }})


原创粉丝点击