怎样实输入框的条件显示(有时候能输入有时候不能输入) 我两个raido类型的输入和一个text类型的输入,目前我想要在radio1。checked=true的时候才能想text框中输入文字,否则设置text为readonly类型,请问我该怎样实现。多谢大家! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我想在点击radio1或radio2的时候text输入框的属性就跟着变化,怎样来实现这样的功能呢? 试试这个:<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"> document.getElementById('test').disabled='true';确实可以使输入框不能输入,但是同时会出现一个问题:有时候这个输入框中是有值的,我想要读出该值,但是设置为disabled后,我就不能读了。为了解决上面的问题,我想把这个输入框设为readonly状态,我用document.getElementById("text").readonly=true; 可是发现没有改变其属性,这是怎么回事? 试试这个document.getElementById('test').setAttribute('readonly',true); <!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> 也就是document.getElementById('test').readonly='readonly';和document.getElementById('test').readonly='';的切换 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为什么不管用啊?求解中! 我应该如何设置我的checkbox为只读属性? 另外我想读取该复选框中的内容,我用$node_xml.="<c_rtag>".$_REQUEST['S_metric'']."</c_rtag>";结果读出来到是<c_rtag>on</c_rtag>,这样的结果对吗? 问题解决啦,确实是读出了“on”我后来又根据条件判断是否==“on”做了相应的处理多谢各位的帮忙! 分时间段处理策略? PHP正则表达式 请教这样的网址是怎么生成的? smarty教程打包下载,整理成CHM格式的供大家学习 utf-8编码下既有繁体又有日文,转成big5编码,日文转不了 求一正则表达式相关代码 关于在网页上向服务器端的文件写内容 PHP4如何安装才可以支持ORACLE9。2!!! 在用PHP编的页面程序中如何调用用c语言编的程序或函数? 为什么在PHP4+IIS5里session不能使用? 一个正则的难点问题(或许很简单) 要求比较高的正则表达式
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">
为了解决上面的问题,我想把这个输入框设为readonly状态,我用document.getElementById("text").readonly=true; 可是发现没有改变其属性,这是怎么回事?
document.getElementById('test').setAttribute('readonly',true);
<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>
document.getElementById('test').readonly='readonly';
和
document.getElementById('test').readonly='';
的切换
<INPUT id="S_metric" name="S_metric" type=checkbox><SPAN>度量值:</SPAN></input>
我用document.getElementById('S_metric').setAttribute('readonly',true);来设置我的checkbox为什么不管用啊?求解中!
我后来又根据条件判断是否==“on”做了相应的处理
多谢各位的帮忙!