Considering the following, how can i enable a disabled element on click?
$("element").click(function(){
//enable element
});
The best I could come up with is:
$('label').click(
function(){
$(this).next(':disabled').removeAttr('disabled');
});
Since the disabled element itself doesn't, at least in Chrome 8/Ubuntu 10.10, respond to click events.
This does assume, of course, that the label
precedes the disabled element, and doesnt', in its current form, check that the label corresponds to the next disabled element.
Edited to revise the approach, so clicking on the label
affects only the relevant input
:
$('label').click(
function(){
var relevantInput = $(this).attr('for');
$('#' + relevantInput)
.removeAttr('disabled');
});
重复: 禁用输入时的Jquery事件。
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.