我想实现这样的功能:<input type="checkbox" name="hmd" value="1" onclick="heidan(this);" />
启动黑名单设置
   <a id="hd1">设置黑名单</a>function heidan(th){

if(th.checked == true){
document.getElementById("hd1").href="javascript:opens()";
}else{
document.getElementById("hd1").href=false;//取消href不能点击
}
}  

解决方案 »

  1.   

    if (th.checked == true) {
        document.getElementById("hd1").href = "javascript:opens()";
    } else {
        document.getElementById("hd1").setAttribute("href", "#");
    }
      

  2.   


    <html>
    <head>
    <script type="text/javascript">
    function heidan(th)
    {
     if(th.checked == true){
     alert("22");
    document.getElementById("hd1").href="javascript:opens()";
    }else{
    alert("111");
    document.getElementById("hd1").href=false;//取消href不能点击
    }
    }
    </script>
    </head>
    <body>
    <input type="checkbox" name="hmd" value="1" onclick="heidan(this);" /> <a id="hd1" href="http://www.baidu.com">aaaaaaa</a>
    </body>
    </html>
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function a(c)
    {
       if(c.checked)
       {
            document.getElementById("aa").onclick=t;
       }else
       {
        document.getElementById("aa").onclick=y;
       }
    }
    function t()

       alert("ttt");
    }
    function y()
    {
    return false;
    }
    //-->
    </SCRIPT>
     <BODY>
     <input type="checkbox" onclick="a(this)">sdfdsfsf
      <a href="#" id="aa">dfdfdfd</a>
     </BODY>
    </HTML>
      

  4.   

    if (th.checked == true) {
        document.getElementById("hd1").href = "javascript:opens()";
    } else {
        //document.getElementById("hd1").setAttribute("href", "#");//这样会刷新页面的
        document.getElementById("hd1").href = "javascript:";//这个不刷
    }
      

  5.   

    <input type="checkbox" name="hmd" value="1" onclick="heidan(this);" />
    启动黑名单设置
      <a id="hd1">设置黑名单</a>function heidan(th){if(th.checked == true){
    document.getElementById("hd1").href= "javascript:opens()";
    //or document.getElementById("hd1").setAttribute("href", "javascript:opens()");
    }else{
    document.getElementById("hd1").href= "javascript:void(0)";;//取消href不能点击
    ////or document.getElementById("hd1").setAttribute("href", "javascript:void(0)");
    }
    }  
      

  6.   

    <input type="checkbox" name="hmd" value="1" onclick="heidan(this);" />
    启动黑名单设置
      <a id="hd1">设置黑名单</a>function heidan(th){if(th.checked == true){
    document.getElementById("hd1").href= "javascript:opens()";
    //or document.getElementById("hd1").setAttribute("href", "javascript:opens()");
    }else{
    document.getElementById("hd1").href= "javascript:void(0)";;//取消href不能点击
    //or document.getElementById("hd1").setAttribute("href", "javascript:void(0)");
    }