zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js控制input框只读实现示例

JS控制 实现 示例 input 只读
2023-06-13 09:15:16 时间
复制代码代码如下:

<html>
<head>
<title>NewDocument</title>
<metaname="Generator"content="EditPlus">
<metaname="Author"content="">
<metaname="Keywords"content="">
<metaname="Description"content="">
</head>
<scriptlanguage="JavaScript">
functionisreadonly(){
varobj=document.getElementById("username");
obj.setAttribute("readOnly",true);
obj.style.backgroundColor="#d2d2d2";
}
functionreadwrite(){
varobj=document.getElementById("username");
obj.setAttribute("readOnly",false);
obj.style.backgroundColor="#ffffff";
}
</script>
<body>
<formname="addform"id="addform"method="post"action="">
<inputtype="text"id="username"name="username">
<inputtype="button"name="只读"value="read"onclick="isreadonly();">
<inputtype="button"name="可写"value="write"onclick="readwrite();">
</form>
</body>
</html>
<!--
点击“read”按钮,input框不能书写,且变灰;点击“write”按钮,input框恢复。
-->