html form 不加name,HTML Form name用法及代码示例

本文详细介绍了HTML中Form对象的name属性,包括如何使用它来返回和设置表单的名称。通过示例代码展示了如何在JavaScript中通过DOM操作获取及修改name属性值,并列举了该属性在不同浏览器中的兼容性情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

它用于返回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;

}

输出:

在单击按钮之前:

25fdbed36431e29dc1af3ab55a98bea7.png

单击按钮后:

0725af3e5cad300985387e184e5b2b16.png

示例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;

}

输出:

在单击按钮之前:

64d58b2c719840d2a692adbc8f273326.png

单击按钮后:

42c3b07b24f6db9a8c1cef63f31ec926.png

支持的浏览器:下面列出了DOM表单名称属性支持的浏览器:

谷歌浏览器

IE浏览器

Firefox

Opera

Safari

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值