如何使用JQuery使文本框启用和禁用更改 [英] How to make textbox enable and disable on change using JQuery
本文介绍了如何使用JQuery使文本框启用和禁用更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段html代码以及脚本代码。我需要解决方案来处理在另一个文本字段中禁用输入数据的行为的一个文本框的更改事件。任何人都可以帮助我。
< div id =ccaclass =leaf>
< label class =control input texttitle =>
< span class =wrap> cca< / span>
< input class =type =textvalue =[Null]/>
< span class =warning>< / span>
< / label>
< / div>
< div id =ccitclass =leaf>
< label class =control input texttitle =>
< span class =wrap> ccit< / span>
< input class =type =textvalue =[Null]/>
< span class =warning>< / span>
< / label>
< / div>
$ (document).ready(function(){
alert(hello);
$(#cca)。on('change','label.control input',function(event) {
alert('我很确定文本框改变了');
$(ccit)。prop('disabled',true);
event.preventDefault();
});
});
解决方案
('change','label.control input',function(())$($#$ $ $code $事件){
alert('我很确定文本框已更改');
$(#ccit)。find('label.control input')。prop('disabled',true );
event.preventDefault();
});
});
# $(ccit)
<$ c $($)$($#$)$($#$)$($#$)我确信文本框改变了');
$(#ccit)。prop('disabled',true);
event.preventDefault();
});
});
更新
('change','label.control input',function(())$($#$ $ $code $事件){
alert('我很确定文本框已更改');
$(#ccit)。find('label.control input')。prop('disabled',true );
event.preventDefault();
});
});
更新2
$(document).ready(function(){
$(document).on('change','#cca label.control input ',function(event){
alert('我很确定文本框已更改');
$(#ccit)。find('label.control input')。prop('禁用',true);
event.preventDefault();
});
});
I have piece of html code as well as script code. I need solution to handle on change event of one text box that disable act of inputting data in another text field. Could any one help me in regarding.
<div id="cca" class="leaf">
<label class="control input text" title="">
<span class="wrap">cca</span>
<input class="" type="text" value="[Null]"/>
<span class="warning"></span>
</label>
</div>
<div id="ccit" class="leaf">
<label class="control input text" title="">
<span class="wrap">ccit</span>
<input class="" type="text" value="[Null]"/>
<span class="warning"></span>
</label>
</div>
$(document).ready(function () {
alert("hello");
$("#cca").on('change', 'label.control input', function (event) {
alert('I am pretty sure the text box changed');
$("ccit").prop('disabled',true);
event.preventDefault();
});
});
解决方案
For one you were missing #
on your $("ccit")
$(document).ready(function () {
alert("hello");
$("#cca").change(function(){
alert('I am pretty sure the text box changed');
$("#ccit").prop('disabled',true);
event.preventDefault();
});
});
Update
$(document).ready(function () {
$("#cca").on('change', 'label.control input', function (event) {
alert('I am pretty sure the text box changed');
$("#ccit").find('label.control input').prop('disabled',true);
event.preventDefault();
});
});
Update 2
$(document).ready(function () {
$(document).on('change', '#cca label.control input', function (event) {
alert('I am pretty sure the text box changed');
$("#ccit").find('label.control input').prop('disabled',true);
event.preventDefault();
});
});
这篇关于如何使用JQuery使文本框启用和禁用更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文