Latest web development tutorials

HTML DOM Password value 屬性

Password 對象參考手冊 Password對象

定義和用法

value 屬性可設置或者返回密碼域的value屬性值。

出於安全考慮,一些瀏覽器可能阻止JavaScript 代碼讀取value 屬性。

語法

設置value 屬性:

passwordObject.value="value"

返回value 屬性:

passwordObject.value


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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


實例

實例

下面的例子可獲得密碼域的默認值:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("pwd").value;
    alert(x);
}
</script>
</head>
<body>

<form>
密码: <input type="password" id="pwd">
</form>
<button type="button" onclick="displayResult()">显示值</button>

</body>
</html>

嘗試一下»


Password 對象參考手冊 Password對象