复制代码代码如下:
<html>
<头>
<title>新文档</title>
<meta name =“ generator” content =“ editplus”>
<meta name =“作者” content =“”>
<meta name =“关键字” content =“”>
<meta name =“描述” content =“”>
</head>
<脚本语言=“ javascript”>
函数isReadonly(){
var obj = document.getElementById(“用户名”);
obj.setAttribute(“ readonly”,true);
obj.style.backgroundColor =“#D2D2D2”;
}
函数readwrite(){
var obj = document.getElementById(“用户名”);
obj.setAttribute(“ readonly”,false);
obj.style.backgroundColor =“#ffffff”;
}
</script>
<身体>
<form name =“ addform” id =“ addform” method =“ post” action =“”>
<input type =“ text” id =“ username” name =“用户名”>
<input type =“ button” name =“只读”值=“读” onclick =“ isreadonly();”>
<input type =“ button” name =“可写” value =“ write” onclick =“ readwrite();”>
</form>
</body>
</html>
<! -
点击“读”按钮,输入框不能书写,且变灰;点击“写”按钮,输入框恢复。
- >