当前位置:Gxlcms > JavaScript > 通过js设置所有form对象为只读

通过js设置所有form对象为只读

时间:2021-07-01 10:21:17 帮助过:4人阅读

例子,设置form中所有对象为只读

<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>
Gxl网,欢迎大家的光临。
<script language="javascript">
//初始化
DisableDiv('p1')
</script>
</html>

相关文章:

js设置input文本框只读

处理表单使input等文本框为只读不可编辑的方法

使用js动态控制input框的只读属性

以上就是通过js设置所有form对象为只读的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行