Here is a fiddle that has a working demo of solution to your problem.
jQuery 1.6+
To change the disabled
property you should use the .prop()
function.
$("#submit").prop('disabled', true);
$("#submit").prop('disabled', false);
jQuery 1.5 and below
The .prop()
function doesn't exist, but .attr()
does similar:
Set the disabled attribute.
$("#submit").attr('disabled','disabled');
To enable again
$("#submit").removeAttr('disabled');
In any version of jQuery
You can always rely on the actual DOM object and is probably a little faster than the other two options if you are only dealing with one element:
// assuming an event handler thus 'this'
this.disabled = true;
The advantage to using the .prop()
or .attr()
methods is that you can set the property for a bunch of selected items.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…