js 获取readOnly属性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript"> <!-- function tomodify(form){ alert('kaishi'); for(var i=0;i<form.elements.length;i++){
var e = form.elements[i]; //alert('获取元素name:'+e.name+'readonly:'+e.readOnly); if(e.readOnly){ e.readOnly=false; alert(e.name+'--'+e.readOnly); } }
} //--> </script> </head>
<body> <form action="" method="post" target="_self" > <input name="yin" type="hidden" value="罗庆龙" size="20" maxlength="30" readOnly="true" />
<input name="l" type="text" value="luoqinglong" size="20" maxlength="30" readOnly="true" /> <input name="add" type="button" value="我要修改" onclick="tomodify(this.form);" />
</form> </body> </html>
PS:注意readOnly的大小拼写,不能写成readonly,或ReadOnly,否则会失效。
这个例子同时还可以用于“全选”,遍历表单。