简体   繁体   中英

Can't remove disabled attribute from button

I'm trying to make a button available only if the content of an input changed this way:

$(document).ready(function() {
    $('input[name="tesztinput1"]').keyup(function(){
          alert('Content has been changed');
          if ($(this).val())
          {
            $('input[name="tesztinput3"]').removeAttr('disabled');
          }
        })
});

And in the HTML:

<input name="tesztinput1" type="text"/>
<input name="tesztinput3" type="button" disabled="disabled" value="Click"/>

It properly works if the element which i want to remove disable attribute is a text input aswell but not working on buttons and submit elements. Any idea?

So this part of the code itself seems to be okay I tested every suggestion in the recent answer and no result. What else could block me from executing an action like this?

Use .prop() ,

To disable

 $('input[name="tesztinput3"]').prop('disabled', true);

To enable

 $('input[name="tesztinput3"]').prop('disabled', false);

DEMO

Also read .prop() vs .attr()

好吧,我没有成功解决问题,但我找到了一个解决方法:我使用只读而不是禁用,因为它可以正常工作。

You can use a "Input" rather than "Button":

$('input[name="tesztinput3"]').prop('disabled', false); 

Just work in a "Input".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM