问题
In my Rails app, I use the :disable_with
helper on a form button.
That form works via ajax. If the object is created successfully, I want to keep that button disabled. So in my create.js.erb
file I have: $('#my-button').disabled = true;
.
However, it doesn't work (works fine in the console though).
I suspect its interfering with Rails' JS for the disable_with helper. How can I get around that?
回答1:
Use jQuery's .prop() method to set the disabled
property of the button. In your case, the code should be
$('#my-button').prop('disabled', true);
To prevent the :disable_with
helper from enabling the button again, remove the data-disable-with
attribute from the button:
$('#my-button').removeAttr('data-disable-with');
来源:https://stackoverflow.com/questions/16369337/disabling-button-after-disable-with