jquery操作id简单小技巧 id选择,某段id开头,排除某个id
<html>
<head>
</head>
<body>
<input type="checkbox" id="1Checkbox1" name="1Checkbox1" />
<input type="checkbox" id="1Checkbox2" name="1Checkbox1"/>
<input type="checkbox" id="1dCheckbox3" name="1Checkbox1"/>
<input type="checkbox" id="1Checkbox4" name="1Checkbox1"/>
<input type="checkbox" id="2Checkbox1" name="2Checkbox1"/>
<input type="checkbox" id="3Checkbox1" name="3Checkbox1"/>
<input type="checkbox" id="3Checkbox1" name="3Checkbox1"/>
<input type="checkbox" id="4Checkbox1" name="4Checkbox1"/>
<input type="button" id="5Checkbox1" name="5Checkbox1" onclick="kaishi();"/>
</body>
</html>
js代码:
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script>
$(function(){
$("input[id^='1']").not("#1Checkbox2").click(function(){ //点击id为1开头但不为1Checkbox2的选择框触发事件
alert("点中了id不是1Checkbox2,但以1开头的");
});
//if($("input[name='test']:checked").length >= 3)
});
function kaishi(){
var CheckCount=0;
$("input[id^='1C']").not("#1Checkbox2").each(function(){ //每一个id为1C开头的事件都触发的事件
if($(this).attr("checked")){
CheckCount++;
}
});
alert("选中了符合条件的数量:"+CheckCount);
}
</script>
效果显示: