Home > Article > Web Front-end > Set all form objects to read-only through js
Example, set all objects in form to be read-only.
<html> <body> <script language="javascript"> function DisableDiv(p) { var objs=new Array() var strobj strobj="input|a|button" objs=strobj.split("|") //for循环开始设置form对象为只读 for(k=0;k<objs.length;k++) { obj1=document.getElementById(p).getElementsByTagName(objs[k]) for (var i=0; i<obj1.length; i++) { obj1[i].disabled=true obj1[i].onclick=function() { this.disabled=true return false } obj1[i].onkeypress=function() { this.disabled=true return false } } } } </script> <p id="p1"> <input type="text" name="textfield"> <input type="button" name="Submit" value="点击我" onclick="javascript:alert('click me')"> </p> </body> php中文网,欢迎大家的光临。 <script language="javascript"> //初始化 DisableDiv('p1') </script> </html>
Related articles:
js sets the input text box to be read-only
Process the form to make the input and other text boxes read-only and non-editable Method
Use js to dynamically control the read-only attribute of the input box
The above is the detailed content of Set all form objects to read-only through js. For more information, please follow other related articles on the PHP Chinese website!