js 复选框 勾上 怎么触发一个 事件

js 复选框 勾上 怎么触发一个 事件

我有一个复选框 id=a 我勾上它就alert("勾上了") 用jq 和js 怎么实现?

多个input可以增加一个class,通过class选择器

 <input type="checkbox" class="grp1"/>
<input type="checkbox" class="grp1"/>
<input type="checkbox" class="grp1"/>
...更多
<script>
$('input.grp1').click(function(){
alert(this.checked?"勾上了":"取消了勾选")
});
</script>
function fx(cbx) { if(cbx.checked){ alert("选中后触发 ~"); //这里面写上你要做的事 } }

复选框

心情好,给你写一个,拿走不谢

$('#a').click(function(){
alert("勾上了")
});

window.getDocumentById('Id').onClick = function(){
//事件处理程序;
}

复选框

function fx(cbx) { if(cbx.checked){ alert("选中后触发 ~"); //这里面写上你要做的事 } }

心情好,给你写一个,拿走不谢

$("input[name='xxx']").click(function(){
if(this.checked==true){
$("input[name='xxx']:checkbox").each(function(){
this.checked=true;
})
}else{
$("input[name='xxx']:checkbox").each(function(){
this.checked=false;
})
}
})