我两个raido类型的输入和一个text类型的输入,目前我想要在radio1。checked=true的时候才能想text框中输入文字,否则设置text为readonly类型,请问我该怎样实现。多谢大家!

解决方案 »

  1.   

    我想在点击radio1或radio2的时候text输入框的属性就跟着变化,怎样来实现这样的功能呢?
      

  2.   

    试试这个:<script>
       function myclick1(){
           document.getElementById('test').disabled='';
       }
       
       function myclick2(){
           document.getElementById('test').disabled='true';
       }
       
    </script><input type="radio" name="radio" value="radio1" onclick="myclick1()">radio1
    <input type="radio" name="radio" value="radio2" onclick="myclick2()">radio2<br>
    <input type="text" id="test">
      

  3.   

    document.getElementById('test').disabled='true';确实可以使输入框不能输入,但是同时会出现一个问题:有时候这个输入框中是有值的,我想要读出该值,但是设置为disabled后,我就不能读了。
    为了解决上面的问题,我想把这个输入框设为readonly状态,我用document.getElementById("text").readonly=true; 可是发现没有改变其属性,这是怎么回事?
      

  4.   

    试试这个
    document.getElementById('test').setAttribute('readonly',true);
      

  5.   

    <!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=utf-8">
    <title> - </title>
    <script type='text/javascript' src="@bak/jquery-1.5.2.min.js"></script>
    <script type='text/javascript'>$(function(){
    $('#c1').click(function(){
    $('#t1').attr('readonly','readonly');
    })
       
    $('#c2').click(function(){
    $('#t1').attr('readonly');
    })
    });
    </script>
    </head><body>
    <input type="radio" name="radio" value="radio1" id="c1">radio1
    <input type="radio" name="radio" value="radio2" id="c2">radio2<br>
    <input type="text" id="t1">
    </body>
    </html>
      

  6.   

    也就是
    document.getElementById('test').readonly='readonly';

    document.getElementById('test').readonly='';
    的切换
      

  7.   

    document.getElementById('test').setAttribute('readonly',true);这个语句确实管用,谢谢楼上的兄弟。我还有一个问题,我用一个
    <INPUT id="S_metric" name="S_metric"  type=checkbox><SPAN>度量值:</SPAN></input>
    我用document.getElementById('S_metric').setAttribute('readonly',true);来设置我的checkbox为什么不管用啊?求解中!
      

  8.   

    我应该如何设置我的checkbox为只读属性?
      

  9.   

    另外我想读取该复选框中的内容,我用$node_xml.="<c_rtag>".$_REQUEST['S_metric'']."</c_rtag>";结果读出来到是<c_rtag>on</c_rtag>,这样的结果对吗?
      

  10.   

    问题解决啦,确实是读出了“on”
    我后来又根据条件判断是否==“on”做了相应的处理
    多谢各位的帮忙!