如何使复选框在多种情况下启用和禁用文本框 [英] how to make a checkbox enable and disable a text box in multiple cases

查看:139
本文介绍了如何使复选框在多种情况下启用和禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了这样的事情。

 < html> 
< head>
< script type =text / javascript>
<! -
function toggleTB(what){
if(what.checked){document.theForm.theTB.disabled = 1}
else {document.theForm。 theTB.disabled = 0}}
// - >
< / script>
< / head>
< body>
< form name =theForm>
< input type =checkboxname =theCBonClick =toggleTB(this)>切换文本框< br>
< input type =textname =theTBvalue =asdf>
< / form>
< / body>
< / html>

但是这只用了一次。我需要在另一行反复使用这个函数也是如此

我的表单是这样的:

 < tr> 
< td style =border-top:none; text-decoration:underline; >特定操作/程序< / td>
< td>
< input type =checkboxname =sd3 []value =mfi_nam9/>其他(请注明):
< input type =textname =mfi_nam9 class =text requiredid =mfi_name
< / td>
< / tr>
< tr>
< td style =border-top:none; text-decoration:underline; >一般原则/策略< / td>
< td>
< input type =checkboxname =sd2 []value =mfi_nam8/>其他(请注明):
< input type =textname =mfi_nam8 class =text requiredid =mfi_name
< / td>
< / tr>

我会等待你的回复,我非常感谢你们以前帮助我,并希望这段时间你也会帮助我。

解决方案

阅读 article

我更喜欢jQuery



这是 DEMO



另一个DEMO

I have done something like this.

<html>
<head>
<script type="text/javascript">
<!--
function toggleTB(what){
if(what.checked){document.theForm.theTB.disabled=1}
else{document.theForm.theTB.disabled=0}}
//-->
</script>
</head>
<body>
<form name="theForm">
<input type="checkbox" name="theCB" onClick="toggleTB(this)">Toggle The Text Box<br>
<input type="text" name="theTB" value="asdf">
</form>
</body>
</html>

But this is only used for one time.i need this function repeatedly in another rows also so how can i used this function for multiple times.

My form goes like this:

 <tr>    
 <td style="border-top:none; text-decoration:underline;" >Specific operations/procedures</td>
 <td>
 <input type="checkbox" name="sd3[]" value="mfi_nam9" />Other(please specify):
 <input type="text" name="mfi_nam9" class="text required" id="mfi_name" 
 </td>
 </tr>
 <tr>    
 <td style="border-top:none; text-decoration:underline;" >General principles/strategies</td>
 <td>
 <input type="checkbox" name="sd2[]" value="mfi_nam8" />Other(please specify):
 <input type="text" name="mfi_nam8" class="text required" id="mfi_name" 
 </td>
 </tr>

i will be waiting for ur response and i am very thankful to u guys for helping me previously and hope u will help me this time too.

解决方案

Read this article

i would prefer jQuery

Here is DEMO

Another DEMO

这篇关于如何使复选框在多种情况下启用和禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆