首页 > 语言 > JavaScript > 正文

js控制input框只读实现示例

2024-05-06 15:59:10
字体:
来源:转载
供稿:网友
控制input框只读可以防止用户对数据的更改,在某些情况下还是比较实用的,下面使用js来完成这个只读实现

复制代码 代码如下:


<html>
<head>
<title> New Document </title>
<meta content="EditPlus">
<meta content="">
<meta content="">
<meta content="">
</head>
<script language="JavaScript">
function isreadonly(){
var obj = document.getElementById("username");
obj.setAttribute("readOnly",true);
obj.style.backgroundColor="#d2d2d2";
}
function readwrite(){
var obj = document.getElementById("username");
obj.setAttribute("readOnly",false);
obj.style.backgroundColor="#ffffff";
}
</script>
<body>
<form method="post" action="" >
<input type="text">
<input type="button" value="read">
<input type="button" value="write">
</form>
</body>
</html>
<!--
点击“read”按钮,input框不能书写,且变灰;点击“write”按钮,input框恢复。
-->

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选