javascript 控制 text 的 readonly 属性

来源:互联网 发布:绍兴黄酒 知乎 编辑:程序博客网 时间:2024/05/16 06:46
<html>  
<head> 
  <title>Test</title> 
</head> 
<body> 
  <form action="" method="post" name="form1"> 
    <input type="text" value="test" id="txtTest" readonly> 
    <input type="button" value="ChangeProperties" onClick="changeText();"> 
  </form> 
</body> 
<script type="text/javascript">
<!--  
function changeText(){  
 var t=document.getElementById("txtTest");  
 if(t.readOnly){ // 注意 readOnly 的 O为大写  
   t.readOnly=false;  
   t.value="write able";  
 }else{  
   t.readOnly=true;  
   t.value="readonly";  
 }  
}  
// -->
</script> 
</html>

原创粉丝点击