HTML DOM Input Checkbox name 屬性
HTML DOM Input Checkbox name 屬性返回一個字串,它是 input checkbox 的 name 屬性的值。使用者還可以將其設定為一個新的字串。
語法
以下是語法 −
- 返回字串值
inputCheckboxObject.name
- 將name 屬性設定為字串值
inputCheckboxObject.name = ‘String’
示例
讓我們看一個 Input Checkbox name 屬性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Name Attribute of Checkbox</title>
</head>
<body>
<form id="Form">
<div>
Enable new name: <input id="formID" type="checkbox" name="formID">
</div>
</form>
<button onclick="getFormID()">Change Name Attribute</button>
<div id="nameAttr"></div>
<script>
function getFormID(){
var oldNameAttr = document.getElementById("formID");
var newNameAttr = document.getElementById("nameAttr");
if(oldNameAttr.checked == true){
oldNameAttr.name = 'newFormID';
newNameAttr.textContent = 'Updated value of name attribute: '+oldNameAttr.name;
} else {
newNameAttr.textContent = 'Check the checkbox'+ ', current value of name attribute: '+oldNameAttr.name ;
}
}
</script>
</body>
</html>輸出
這將產生以下輸出 −
在勾選“啟用新名稱”複選框之前 −

勾選“啟用新名稱”複選框之後 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP