如何通过js函数去设定复选框只读?
(是只读而不是禁用!)<input name="checkbox" type="checkbox" value="checkbox" onclick="return false;">
onclick="return false;" 方法除外必须是js函数实现,因为我需要判断某种情况下该复选框只读!谢谢大侠相助!

解决方案 »

  1.   

    document.getElementById("你input的id").disabled="disabled"
      

  2.   

    <!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 type="text/javascript">
    function change(){
    var c=document.getElementsByName("checkbox");
    for(var i=0;i<5;i+=2){
    c[i].disabled="disabled";
    }
    }
    </script>
    </head><body>
    <input name="checkbox" type="checkbox" value="checkbox" readonly="">
    <input name="checkbox" type="checkbox" value="checkbox">
    <input name="checkbox" type="checkbox" value="checkbox">
    <input name="checkbox" type="checkbox" value="checkbox">
    <input name="checkbox" type="checkbox" value="checkbox">
    <input type="button" onclick="change()" value="1,3,5只读">
    </body>
    </html>
    类似这样?
      

  3.   

    也不是楼上理解的那样比如:<input type="radio" name="test" value=1 onclick="return false;">1<br>
    <input type="radio" name="test" value=2 onclick="return false;">2<br>
    <input type="checkbox" name="test2">3
    <script>
    function document.onclick(){
    if(event.srcElement.type=="radio"||event.srcElement.type=="checkbox"){
    return false;
    }
    }
    </script>
    现在的这段代码就是只读,但不禁用的。但是问题是如果这样的话会导致复选框一直处于只读状态,我只希望在一定判断条件下只读。
      

  4.   

    因为如果灰色不可用,POST的时候就不会把该复选框的值一起传递了
      

  5.   

    <input type="checkbox" name="test2">3
    <script type="text/javascript">
    var chk = document.getElementsByName("test2")[0];
    var checked = chk.checked;
    chk.onchange = function(){
    chk.checked = checked;
    }
    </script>