Password readOnly 屬性

定義和用法
readOnly 屬性可設置或返回密碼域是否為只讀。
只讀字段不能被修改。但是,用戶可以選中它並複製文本。
語法
設置 readOnly 屬性:
passwordObject.readOnly=true|false
返回 readOnly 屬性:
passwordObject.readOnly
流覽器支持
所有主要流覽器都支持 readOnly 屬性
實例
實例
下麵的例子把密碼域設置為只讀:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
密碼: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">設置只讀</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
密碼: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">設置只讀</button>
</body>
</html>
