一、checkbox选中用法
问题:如果一个select的改变事件的选中的值改变,那么相应的复选框也要选中或者取消,
$("#isfourfive").change(function () {
var val=$("#isfourfive option:selected").val();
if(val=="是"){
$("#sel5").attr("checked", true);
}else{
$("#sel5").removeAttr("checked");
}
});
但是这样会遇到一个问题:第二次选中是走改变事件的时候,属性checked可以加到代码中,
但是却没有对勾,所以应该吧.attr改成.prop就好了。
$("#sel5").prop("checked", true);
参考路径:http://blog.csdn.net/u012124564/article/details/47837615
1、properties和attributes都有表示“属性”的意思
2、从1.5.2升级到1.6.1 两个版本有区别
3、首选用法的概述
.prop()方法应该被用来处理boolean attributes/properties以及在html(比如:window.location)中不存在的properties。其他所有的attributes(在html中你看到的那些)可以而且应该继续使用.attr()方法来进行操作。
二、
获取name为textname的所有未选中的checkbox
var unCheckedBoxs = $("input[name='textname']").not("input:checked");