禁用复选框上的输入 [英] disable input on check checkbox

查看:104
本文介绍了禁用复选框上的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的代码如下所示:

 < div class =y> 
< input type =checkboxclass =myCheck/>
< input type =selectname =xclass =mySelect/>
< / div>

< div class =y>
< input type =checkboxclass =myCheck/>
< input type =selectname =xclass =mySelect/>
< / div>

< div class =y>
< input type =checkboxclass =myCheck/>
< input type =selectname =xclass =mySelect/>
< / div>

但我想禁用并启用与复选框相对应的选择输入。如果用户在第一个复选框中单击,则启用第一个输入,并在第二个和第三个输入中执行相同的操作。 解决方案

/ p>

 < script src =https://ajax.googleapis.com/ajax/libs/jquery/2.1。

p>

参考文献

。next()



.prop( )


Need to disable an input when the check-box is unchecked, and when it is checked enable it.

My code is like this:

<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>

<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>

<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>

But I want to disable and enable the select input which correspond to a check-box. If user clicks in first check box enable first input, and do the same for second and third.

解决方案

One simple solution:

$(".mySelect").prop("disabled", true);

$("input:checkbox").on("change", function () {
    $(this).next().prop("disabled", !$(this).prop("checked"));
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>
<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>
<div class="y">
    <input type="checkbox" class="myCheck" />
    <input type="select" name="x" class="mySelect" />
</div>

References

.next()

.prop()

这篇关于禁用复选框上的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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