使用按钮单击启用和禁用文本框 [英] enable and disable textbox by using button click
本文介绍了使用按钮单击启用和禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个文本框...每个文本框都有自己的按钮来启用或禁用。
如何操作?
我已经试过这个
$('#disablebutton')。click(function(){
$('#textfieldToClose')。attr('disable');
});
< input type =textname =text11readonly =readonlyid =textfieldToClose>
< input type =buttonvalue =editname =button1id =disablebutton>
解决方案
试试:
$(document).ready(function(){
$('#disablebutton')。click(function(){
if $('#textfieldToClose')。prop('disabled'))
{
$('#textfieldToClose')。prop('disabled',false)
}
else {
$('#textfieldToClose')。prop('disabled',true)
}
});
})
或只读: ).ready(function(){
$('#disablebutton')。click(function(){
if($('#textfieldToClose')。prop('readonly'))
{
$( '#textfieldToClose')removeAttr( '只读');
}
,否则{
$( '#textfieldToClose')ATTR( '只读', 'readonly')
}
});
});
因为您只选择attr,但不要做任何事情。
现场演示
I have multiple of textbox...each textbox have own button to enable or disable . How to do it ? I have already try this
$('#disablebutton').click(function(){
$('#textfieldToClose').attr('disable');
});
<input type="text" name="text11" readonly="readonly" id="textfieldToClose">
<input type="button" value="edit" name="button1" id="disablebutton">
解决方案
Try:
$(document).ready(function(){
$('#disablebutton').click(function(){
if($('#textfieldToClose').prop('disabled'))
{
$('#textfieldToClose').prop('disabled', false)
}
else{
$('#textfieldToClose').prop('disabled', true)
}
});
})
or with Read only:
$(document).ready(function(){
$('#disablebutton').click(function(){
if($('#textfieldToClose').prop('readonly'))
{
$('#textfieldToClose').removeAttr('readonly');
}
else{
$('#textfieldToClose').attr('readonly', 'readonly')
}
});
});
Because you only select the attr but, don't do anything with. Live demo
这篇关于使用按钮单击启用和禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文