[英]How to make non editable text box to editable when i click on check box corresponding to it
There are one check box and a non editable text box corresponding to it. 有一个复选框和与之对应的一个不可编辑的文本框。 When I click on check box, corresponding non editable text box should become an editable text box.
当我单击复选框时,相应的不可编辑文本框应成为可编辑文本框。 How can I achieve this?
我该如何实现?
Basically: 基本上:
$('#some-checkbox').click(function() {
$('#some-textfield').prop('disabled', !$(this).is(':checked'));
});
Now, how you go about finding the corresponding text box depends on your markup. 现在,如何查找相应的文本框取决于您的标记。 One way could be to give the text box a class that is the ID of the checkbox.
一种方法是为文本框提供一个类,该类为复选框的ID。 Applying that to all checkboxes might look something like this:
将其应用于所有复选框可能看起来像这样:
$(':checkbox').click(function() {
var box = $(this);
$('.' + box.attr('id')).prop('disabled', !box.is(':checked'));
});
Otherwise, the text field may be located by its position on the DOM: 否则,可以通过其在DOM上的位置来定位文本字段:
<div class="wrapper">
<input type="checkbox">
...
<div>
<input type="text" disabled="disabled" />
</div>
</div>
You might then do something like: 然后,您可以执行以下操作:
$(':checkbox').click(function() {
var box = $(this);
box.closest('.wrapper').find('input[type=text]').prop('disabled', !box.is(':checked'));
});
This code actually works fine, and ready to use. 该代码实际上可以正常工作,并且可以使用。
This is the form stuff: 这是表格内容:
<form id="myGame" name="myGame" action="" method="post">
<input type="radio" name="checkme" id="checkme" onClick="openTheHouse();" >Open Sesame
<input name="open_id" id="openid" type=text disabled="disabled">
</from>
And the Script: its pretty cool actually, nothing complicated in this script. 脚本:实际上非常酷,在此脚本中没有什么复杂的。
<script type="text/javascript">
function openTheHouse()
{
if(document.myGame.checkme.checked == true)
{
document.myGame.openid.disabled = false ;
}
}
</script>
thats it, all done. 就是这样,全部完成。 Certainly i believe it works.
当然,我相信它能奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.