选择框控制文本框?

wu_lin_326 2010-07-02 09:31:06
<td bgcolor="#E8DBE8">
<div align="center"> 
<select name="txt_phonesol">
<option value="0">readonly</option>
<option value="1">text</option>
</select>
</div></td>

<td><div align="center"><input name="txt_tcreason" type=text></div></td>



选择框控制文本框,当我选择readonly是 文本框是readonly的 当我选择text,文本框是可写的

谢谢 初学 线等
...全文
95 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
leejelen 2010-07-02
  • 打赏
  • 举报
回复
楼上正解
Go 旅城通票 2010-07-02
  • 打赏
  • 举报
回复
<!--默认为readonly你加个属性就行了-->
<input name="txt_tcreason" type=text id="txt_tcreason" readonly="readonly"/>
wu_lin_326 2010-07-02
  • 打赏
  • 举报
回复
恩,可以了,还有一个问题就是第一次打开不是readonly的
Go 旅城通票 2010-07-02
  • 打赏
  • 举报
回复
<!--补充1楼代码,少了ID-->
<div align="center"><input name="txt_tcreason" type=text id="txt_tcreason"></div><
wu_lin_326 2010-07-02
  • 打赏
  • 举报
回复
试了试 怎么不管用啊
vnetcbd 2010-07-02
  • 打赏
  • 举报
回复
<td bgcolor="#E8DBE8">
<div align="center"> 
<select name="txt_phonesol" onchange="javascript:document.getElementById('txt_tcreason').type=this.value">
<option value="readonly">readonly</option>
<option value="text">text</option>
</select>
</div></td>

<td><div align="center"><input name="txt_tcreason" type=text></div></td>
lemon520 2010-07-02
  • 打赏
  • 举报
回复

<td bgcolor="#E8DBE8">
<div align="center"> 
<select name="txt_phonesol" onchange="javascript:document.getElementById('txt_tcreason').readOnly=(this.value==0)">
<option value="0">readonly</option>
<option value="1">text</option>
</select>
</div></td>

<td><div align="center"><input name="txt_tcreason" type=text></div></td>
Meteoric_cry 2010-07-02
  • 打赏
  • 举报
回复

<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>

<body>
<select name="txt_phonesol" id="txt_phonesol">
<option value="0">readonly</option>
<option value="1">text</option>
</select>

<input name="txt_tcreason" type='text' id="txt_tcreason"></div>
<script type="text/javascript">
function $(id) {
return typeof id === 'string' ? document.getElementById(id) : id;
}

$("txt_phonesol").onchange = function() {
var iptElem = $('txt_tcreason');

if(this.value == "1") {
iptElem.removeAttribute("readOnly");
iptElem.focus();
iptElem.style.backgroundColor = '#FFFFFF';
} else {
iptElem.setAttribute("readOnly", true);
iptElem.style.backgroundColor = '#CCCCCC';
}
}

$("txt_phonesol").onchange();
</script>
</body>
</html>


87,920

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧