<td> <select name="paym" id="imo"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <script type="text/javascript"> var a=document.getElementById("imo").value; if (a=="check") document.getElementById("baoxiao").disabled=true; </script> <input type="text" id="baoxiao" maxlength="10" /> </td> 想在选择yyy的情况下让下面的文本框无法输入,但我怎么写始终不成功啊。看了半天也没看出错误。请问是哪里的问题,谢谢了。
回复讨论(解决方案)
楼主是要禁用文本框吗? 给你看一篇博文:利用JQuery自定义扩展来禁用表单元素: http://www.ido321.com/397.html
<td> <select name="paym" id="imo"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <script type="text/javascript"> var a=document.getElementById("imo").value; if (a=="check") document.getElementById("baoxiao").disabled=true; </script> <input type="text" id="baoxiao" maxlength="10" /> </td> 想在选择yyy的情况下让下面的文本框无法输入,但我怎么写始终不成功啊。看了半天也没看出错误。请问是哪里的问题,谢谢了。
<td> <select name="paym" id="imo" onchange="test()"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <script type="text/javascript"> function test(){ var a=document.getElementById("imo").value; if (a=="check") document.getElementById("baoxiao").disabled=true; } </script> <input type="text" id="baoxiao" maxlength="10" /> </td> javascript就没有调用肯定是不成功的
js 是以事件跟用户进行互动的,demo要发完整的代码,这样才有助于你问题的快速解决。
看不懂的地方,百度查一下。都是很基础的一些点。
<!DOCTYPE html><html><head> <meta charset="utf-8"/> <title>test</title> <style type="text/css"> input{ line-height:30px;} .disabled{ border:1px solid #ccc; background: #f1f1f1;} </style></head><body><table> <tr> <td> <select name="paym" id="imo"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <input type="text" id="baoxiao" maxlength="10" /> </td> </tr></table><script type="text/javascript"> var a=document.getElementById("imo"); var txt=document.getElementById("baoxiao"); a.onchange = function(e){ e = e || event; var target = e.target || e.srcElement; if(target.value == 'check'){ txt.className = 'disabled'; txt.disabled = true; } else { txt.className = ''; txt.disabled = false; } }</script></body></html>
js 是以事件跟用户进行互动的,demo要发完整的代码,这样才有助于你问题的快速解决。
看不懂的地方,百度查一下。都是很基础的一些点。
<!DOCTYPE html><html><head> <meta charset="utf-8"/> <title>test</title> <style type="text/css"> input{ line-height:30px;} .disabled{ border:1px solid #ccc; background: #f1f1f1;} </style></head><body><table> <tr> <td> <select name="paym" id="imo"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <input type="text" id="baoxiao" maxlength="10" /> </td> </tr></table><script type="text/javascript"> var a=document.getElementById("imo"); var txt=document.getElementById("baoxiao"); a.onchange = function(e){ e = e || event; var target = e.target || e.srcElement; if(target.value == 'check'){ txt.className = 'disabled'; txt.disabled = true; } else { txt.className = ''; txt.disabled = false; } }</script></body></html> 见教的是,我也是刚开始学,很多地方摸索着来。谢谢您的建议。
<td> <select name="paym" id="imo" onchange="test()"> <option value="money" selected>aaa</option> <option value="check" >yyy</option> <option value="card">xxx</option> </select> </td> </tr> <tr> <th height="10%" width="10%" align="center" bgcolor="#1a60a8" style="border:1px solid #000000;"> <font color="#FFFFFF"><b>bbb</b></font></th> <td> <script type="text/javascript"> function test(){ var a=document.getElementById("imo").value; if (a=="check") document.getElementById("baoxiao").disabled=true; } </script> <input type="text" id="baoxiao" maxlength="10" /> </td> javascript就没有调用肯定是不成功的
呵呵,确实啊。哎,脑子当时有点轴了。没想到这点。谢谢你的提醒啊











