http://www.irenezone.com/devarticles/article.jsf?articleId=1191811918. checkbox复选框,如何让其勾选时触发一个事件,取消勾选时不触发。onclick在勾选和取消勾选都会触发。

解决方案 »

  1.   

    参考连接 http://www.irenezone.com/devarticles/article.jsf?articleId=11918<input type="checkbox" onclick="checkboxOnclick(this)" /><script>function checkboxOnclick(checkbox){if ( checkbox.checked == true){//Action for checked}else{//Action for not checked}}</script>
      

  2.   

    你可以就在onclick里写,判断是被选中了还是没被选中
    如果被选中了就执行你要执行的代码
    如果没选中就什么都不执行,就可以
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script defer="defer">
    function test(){
    var $ = document.getElementById;
    if($('checkBoxId').checked == true){
    alert("选中");
    subMit();
    }
    if($('checkBoxId').checked == false){
    alert("未选中");
    subMit1();
    }
    }
    function subMit(){
    alert("执行选中的函数");
    }
    function subMit1(){
    alert("执行位选中的函数");
    }
    </script>
    </head><body>
    <input type="checkbox" name="checkbox" id="checkBoxId" value="checkbox" />
    选中
    <input name="" value="执行" type="button" onclick="test()" />
    </body>
    </html>
      

  4.   

    function checkAll()
    {
    var ch1 = document.getElementsByName("delids");
    for (var i=0;i<ch1.length;i++)
    {
    if (document.all.chek.checked)
    {
    ch1[i].checked=true;
    }
    else
    {
    ch1[i].checked=false;
    }
    }
    }