HTML 元素可以具有与其 [id] 相同的 [name] 吗? [英] Is it ok for an HTML element to have the same [name] as its [id]?

查看:36
本文介绍了HTML 元素可以具有与其 [id] 相同的 [name] 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Satay 方法在网页中嵌入 Flash 应用程序:

I'm working on embedding a flash app in a webpage using the Satay method:

<object type="application/x-shockwave-flash" data="embeddy.swf"
id="embeddy" name="embeddy">
  <param name="movie" value="embeddy.swf" />
</object>

我希望 flash 在 ExternalInterface.objectID 中提供正确的 objectID,这意味着我需要同时设置 nameobject 的 id 属性.

I want flash to provide the correct objectID in ExternalInterface.objectID, which means I need to set both the name and id attributes for the object.

通常我会尽量避免与 HTML 中的元素发生命名冲突,但是在这种情况下将两个属性设置为相同的值有什么问题吗?

Normally I try to avoid naming collisions with elements in HTML, but is there anything wrong with setting both attributes to the same value in this case?

HTML 表单呢?有没有人觉得值得设置一个(n) ( input | select | textarea ) 元素的nameid 属性是否相同?

What about HTML forms? Does anyone feel that it's worthwhile to set a(n) ( input | select | textarea ) element's name and id attributes to the same value?

推荐答案

您使用 ID 进行 JavaScript 操作.

You use IDs for JavaScript manipulation.

您使用名称提交表单字段.

You use Names for form field submission.

两者没有关系.所以将两者设置为相同的值是可以的,但不是必需的.

The two are not related. So setting both to the same value is OK, but it is not required.

这篇关于HTML 元素可以具有与其 [id] 相同的 [name] 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆