HTML DOM中的DOM输入颜色名称属性用于设置或返回名称属性的值。每个输入月字段都需要name属性。如果未在输入字段中指定name属性,则将根本不发送该字段的数据。
用法:
它返回输入颜色名称属性。colorObject.name
它用于设置输入颜色名称属性。colorObject.name = name
属性值:它包含单个属性值,即用于指定“颜色”字段名称的名称。
返回值:它返回一个字符串值,该字符串值表示输入“颜色”字段的名称。
示例1:本示例返回输入颜色名称属性。
HTML DOM Input Color name Property
GeeksForGeeks
HTML DOM Input Color name Property
Select your favorite color:
value="#009900"
name="Geek_color"
id="color">
Click Here!
style="color:green;
font-size:24px;">
function myGeeks() {
var x =
document.getElementById(
"color").name;
document.getElementById(
"GFG").innerHTML = x;
}
输出:
在单击按钮之前:
单击按钮后:
示例2:本示例说明了如何设置名称属性。
HTML DOM Input Color name Property
GeeksForGeeks
HTML DOM Input Color name Property
Select your favorite color:
value="#009900"
name="Geek_color"
id="color">
Click Here!
style="color:green;
font-size:24px;">
function myGeeks() {
var x =
document.getElementById(
"color").name = "Hello Geeks";
document.getElementById(
"GFG").innerHTML =
"The value of the name attribute"+
" was changed to " + x;
}
输出:
在单击按钮之前:
单击按钮后:
支持的浏览器:DOM输入颜色名称属性支持的浏览器如下:
谷歌浏览器
Internet Explorer 10.0以上
Firefox
Opera
Safari