开发者

How to disable empty textboxes in a page using JQuery

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜