var chk = document.getElementById('checkbox的ID');
var edt = document.getElementById('input的ID');
if(chk.checked){
  edt.onfocus=function(){alert("选中");};
}else{
  edt.readOnly=false;
}

解决方案 »

  1.   

    LZ,代码如下,以验证成功:
    <html>
    <head>
    <script type="text/javascript">
    function ckTest(){
    var ck = document.all("ck");
    if(ck.checked){
    alert("获得焦点");
    document.all("txt").focus();
    }else{
    document.all("txt").readOnly=true;
    }
    }
    </script>
    </head>
    <body>
    <input type="text" id="txt" name="txt">
    <input type="checkbox" id="ck" name="ck" value="111" onclick="ckTest()">
    </body>
    </html>
      

  2.   


    <script type="text/javascript">
     function test(bo)  {
    if(bo) {
    document.getElementById("txt1").readOnly=false;
    document.getElementById("txt1").onfocus=function() {
    alert("aaa");
    }
    } else {
    document.getElementById("txt1").onfocus=null;
    document.getElementById("txt1").readOnly=true;
    }
     }
      </script>  
      <label for="chk1"><input type="checkbox" id="chk1" onclick="test(this.checked)" />aa</label><input type="text" readonly id='txt1'/>
      

  3.   

    script type="text/javascript">
     function test(bo)  {
        if(bo) {
            document.getElementById("txt1").readOnly=false;        document.getElementById("txt1").onfocus=function() {
                alert("aaa");
            }
        } else {
            document.getElementById("txt1").onfocus=null;
            document.getElementById("txt1").readOnly=true;
        }
     }
      </script>  
      <label for="chk1"><input type="checkbox" id="chk1" onclick="test(this.checked)" />aa</label><input type="text" readonly id='txt1'/