Is there an event for when an input gets disabled?
For an input extension script I'm making I need an input to tell me when/if it gets disabled. That is, when it's disabled
parameter is set.
Is there an event for this?
If not, how would I emulate the behaviour?
Also I开发者_JAVA技巧'm using jQuery
Ideally, any events that you need to latch on to (and aren't user events - click, mouseover etc.) should be fired programmatically within the code, as opposed to polling the actual DOM, which is the end-representation that your code produces.
DOM mutation events aren't well supported and AFAIK are being deprecated.
From the sounds of what you've said, it seems like the best thing to do would be to check whether the <input>
is disabled upon initiation of your extension/plugin, and then enable plugin/extension users to disable the input via your own API, meaning that you can know when it happens.
A really primitive example would be creating your own disable
method for jQuery:
jQuery.fn.disable = function() {
return this.each(function(){
$(this).attr('disabled', true).triggerHandler('disable');
});
};
// E.g.
var input = jQuery('input#foo');
input.bind('disable', function(){ alert('Foo Disabled!'); });
input.disable();
You can see that we trigger our own event for each element within the disable
method. This is just an example though; I don't really suggest this -- try to keep everything under the namespace of your own plugin/extension.
I am afraid there is no built-in event like that. Using trigger and bind, however, you can create your own event. Custom events in jQuery?
I hope using .attr()
you can find its disabled or not
精彩评论