Home > Web Front-end > JS Tutorial > body text

Set all form objects to read-only through js

阿神
Release: 2017-03-18 11:23:32
Original
2125 people have browsed it

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(&#39;click me&#39;)">
</p>
</body>
php中文网,欢迎大家的光临。
<script language="javascript">
//初始化
DisableDiv(&#39;p1&#39;)
</script>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!