开发者

Making Readonly all fields in a form

How can we make all fields in a form开发者_开发百科 read only ?


This should work:

$(':input').attr('readonly','readonly');

Or if you have a specific form...

$('#myFormID :input').attr('readonly','readonly');

If you are using just plain JavaScript, you'll want to do this.

var f = document.forms['myFormNAME'];
for(var i=0,fLen=f.length;i<fLen;i++){
  f.elements[i].readOnly = true;//As @oldergod noted, the "O" must be upper case
}

One side note... although you can "set" the readonly flag on checkbox and hidden input fields... it won't actually make them readonly.


A solution without javascript, enclose all fields in fieldsets and add disabled tag to fieldsets.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜