HTML DOM Password name 屬性
定義和用法
name 屬性可設置或返回密碼域的名稱。
name 屬性用於表單提交後向服務器傳送數據,或者在Javascript引用表單數據。
注意:在表單提交後只有表單元素的name屬性才會傳遞數據值。
語法
設置name 屬性:
passwordObject.name="name"
返回name 屬性:
passwordObject.name
瀏覽器支持
所有主要瀏覽器都支持name 屬性
實例
實例
下面的例子可獲得密碼域的名稱:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").name;
alert(x);
}
</script>
</head>
<body>
<form>
密碼: <input type="password" id="pwd" name="password">
</form>
<button type="button" onclick="displayResult()">顯示名稱</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").name;
alert(x);
}
</script>
</head>
<body>
<form>
密碼: <input type="password" id="pwd" name="password">
</form>
<button type="button" onclick="displayResult()">顯示名稱</button>
</body>
</html>
嘗試一下»
Password對象