怎样实输入框的条件显示(有时候能输入有时候不能输入) 我两个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怎么入门啊?从哪里开始啊?请教一下各位师兄 json 字符串 转换成php数组 寻求PHP小程序开发 急急急!!!提示错误为: Unknown column 'abc' in 'where clause' 是怎么回事? 请问这个问题怎么实现 求个正则 全部都配置好了,打开 *.php 还是出现下载界面 一用session_start()就出错, 新手请教php如何对文件进行访问、读取内容,排序及显示 诚心交使用php做开发的朋友,希望大家留个msn 一个正则的难点问题(或许很简单) 要求比较高的正则表达式
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”做了相应的处理
多谢各位的帮忙!