html name id, 与服务器交互必须有name

本文详细介绍了HTML中元素的ID和Name属性的区别及使用场景。解释了Name属性主要用在表单元素中用于提交信息,而ID属性则强调唯一性且可用于CSS和JavaScript中进行元素引用。

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

html name id, 与服务器交互必须有name

在HTML中元素的ID和Name的区别和联系。
今天写了个测试,在php脚本里怎么也获取不到$_POST['userName']的值,经检查在html页面只写了input的Id,没有写Name。

现总结网上的帖子:

Name Attribute

Valid only on a, form, iframe, img, map, input, select, textarea
Name does not have to be unique
Can not be referenced in URL
Is referenced in JS with getElementsByName()
Shares same name space as id attribute
Must begin with a letter
Is case sensitive
Used on form elements to submit information

Id Attribute

Valid on any element
Each Id should be unique
Can be used as anchor reference in URL
Is referenced in CSS or URL with # sign
Is referenced in JS with getElementById()
Shares same name space as name attribute
Must begin with a letter
Is case sensitive

参考: 1 http://stackoverflow.com/questions/7470268/html-input-name-vs-id 
2 http://www.cnblogs.com/birdshome/archive/2005/01/31/99562.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值