Latest web development tutorials

HTML DOM Password readOnly 屬性

Password 對象參考手冊 Password對象

定義和用法

readOnly 屬性可設置或返回密碼域是否為只讀。

只讀字段不能被修改。 但是,用戶可以選中它並複製文本。

語法

設置readOnly 屬性:

passwordObject.readOnly=true|false

返回readOnly 屬性:

passwordObject.readOnly


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持readOnly 屬性


實例

實例

下面的例子把密碼域設置為只讀:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>

嘗試一下»


Password 對象參考手冊 Password對象