如果我在一个页面上多次使用相同的#id,除了验证错误“ID已经被定义”,我将面临什么实际问题? [英] What practical problem will i face if i use same #id more than one time on a page , other than validation error "ID is already defined"?

查看:180
本文介绍了如果我在一个页面上多次使用相同的#id,除了验证错误“ID已经被定义”,我将面临什么实际问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我alwyas使用一个#ID。只是问这个问题,知道背后的深层原因。



这只是W3C验证的问题吗?



我会面对任何实际问题,还是只是一个验证的逻辑?



本示例 http://jsbin.com/aniqi 适用于所有浏览器。只是验证给出错误



更新:我认为所有浏览器都支持多个#ID,因此它只是一个推荐,



只有验证产生错误:ID已定义。



如果我们使用javascript来选择#

更新2:如果我的某些网页设计学生向我询问为什么css #ID应该在页面中使用一次学生不知道JavaScript的。我可以给什么原因不要使用#ID多个,



更新3:我在W3C网站上发现了一些有用的信息

 < P id =myparagraph>这是一个唯一命名的段落< / P> 
< P id =yourparagraph> < / P>

id属性在HTML中具有多个角色: / p>

id属性为元素分配一个唯一标识符(可以由SGML解析器验证)。例如,以下段落通过其id值区分: p>

  *作为样式表选择器。 
*作为超文本链接的目标锚点。
*作为从脚本引用特定元素的方法。
*作为声明的OBJECT元素的名称。
*用于用户代理的通用处理(例如,用于在将数据从HTML页面提取到数据库中时标识字段,将HTML文档转换为其他格式等)。


解决方案

有趣的讨论。



它的真实意义.. Id必须是唯一的,并且重复ID的使用必须已被浏览器本身折旧。

但是可能是因为这些浏览器想要使它更加编码友好,不认真考虑id问题。
所以除了javascript这个错误对我们来说也不重要...

(取决于不同浏览器的版本)甚至CSS没有问题..(除了验证错误)检查这个。

 < head> 
< style type =text / css>
#Button {color:red;}
< / style>
< / head>
< body>
< form>
< input id =Buttontype =buttonvalue =点击我/>
< input id =Buttontype =textvalue =Type Here/>
< / form>
< / body>

但我保证在使用javascript的情况下,它容易出现地狱错误。遇到了这个问题,我在ID上使用了相同的名称,以及NAME ..!



: - )


First of all I alwyas use one #ID. just asking this question to know deep reason behind it.

Is it only a matter of W3C validation? or more than that.

Will i face any practical problem or it's just a logic for validation?

see this example http://jsbin.com/aniqi it's working on all browsers. just validation giving error

update : I think all browser supports more than one #ID so it's just a recommendation but supported by browsers.

only validation give error : ID is already defined.

and if we use javascript to select #ID, other wise it's not a problem

Update 2: What should be the answer if some web design students of mine asking to me about "Why css #ID should be used once in a page. student doesn't know about javascript yet. What reasons i can give to not to use #ID more than one, while it's supported by all browsers?

Update 3: I found some useful info on W3C site

<P id="myparagraph"> This is a uniquely named paragraph.</P>
<P id="yourparagraph"> This is also a uniquely named paragraph.</P>

The id attribute has several roles in HTML:

The id attribute assigns a unique identifier to an element (which may be verified by an SGML parser). For example, the following paragraphs are distinguished by their id values:

* As a style sheet selector.
* As a target anchor for hypertext links.
* As a means to reference a particular element from a script.
* As the name of a declared OBJECT element.
* For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).

解决方案

This post is just to add some more points to this interesting discussion ..

Its true that .. Id must have been unique and usage of 'duplicate IDs' must have been depreciated by browsers itself ..
But may be because these browsers want to make it more coder-friendly, don't seriously consider the "id" matter ..
So apart from javascript this mistake doesn't matter much to us too ...
(Depends on the version of the different browsers) Even CSS has no problem with it .. (apart from validation errors) check this out ..

<head>
<style type="text/css">
  #Button{color:red;}
</style>
</head>
<body>
<form>
<input id="Button" type="button" value="Click me"/>
<input id="Button" type="text" value="Type Here"/>
</form>
</body>

But I assure that in-case of javascript usage it is prone to hell of bugs .. Once I had faced this problem .. where I had used same name for ID as well as NAME .. !

:-)

这篇关于如果我在一个页面上多次使用相同的#id,除了验证错误“ID已经被定义”,我将面临什么实际问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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