I h开发者_运维百科ave a page with many panels. each panel will have around 5 textboxes. I need to disable all the textboxes which are empty when the page is loaded. Want to acieve this using JQuery. Can somebody help me on this?
This should do it:
$(function(){
$('input[type="text"]').each(function(){
if ($(this).val() === '') {
$(this).attr('disabled', 'disabled');
}
});
});
If you have applied some class to your textboxes, you can also do:
$(function(){
$('.class_name').each(function(){
if ($(this).val() === '') {
$(this).attr('disabled', 'disabled');
}
});
});
var empties = $('input:text').filter(function() {
return this.value == ''; // If the value of the input is empty,
}); // add it to the collection
empties.attr('disabled','disabled'); // Then disable the collection of empties
精彩评论