它用于返回name属性。formObject.name
它用于设置name属性。formObject.name = name
属性值
name:它指定表单的名称。
返回值:它返回一个代表表单名称的字符串值。
示例1:说明如何返回属性的HTML程序。
GeeksForGeeks
DOM Form name Property.
action="#"
name="Geeks">
First name:
name="fname"
value="Manas">
Last name:
name="lname"
value="Chhabra">
value="Submit">
Click the "Try it" button to return
the name of the Form
Try it
style="font-size:25px;color:green;">
function myGeeks() {
// Return the property
var x = document.getElementById(
"users").name;
document.getElementById("sudo").innerHTML =
"The name of the Form is " + x;
}
输出:
在单击按钮之前:
单击按钮后:
示例2:说明如何设置属性的HTML程序。
GeeksForGeeks
DOM Form name Property.
action="#"
name="Geeks">
First name:
name="fname"
value="Manas">
Last name:
name="lname"
value="Chhabra">
value="Submit">
Click the "Try it" button to
set the name of the Form
Try it
style="font-size:25px;
color:green;">
function myGeeks() {
// Set the name attribute value.
var x = document.getElementById(
"users").name = "users";
document.getElementById("sudo").innerHTML =
"The value of the name attribute was changed to "
+ x;
}
输出:
在单击按钮之前:
单击按钮后:
支持的浏览器:下面列出了DOM表单名称属性支持的浏览器:
谷歌浏览器
IE浏览器
Firefox
Opera
Safari