English 中文(简体)
它是用于 j的Valid超文本
原标题:is this Valid HTML for jquery

我有以下超文本。

div#main-content div#right-col div#post-show div#post-img div#post-img-large{

}
div#main-content div#right-col div#post-show div#post-img div#post-img-large 
   img#post-img-large{
}

你可以看到,我用同样的补贴来iv和 im。

这是否允许? 我知道它会做些细微的工作,但是如果提及id后lar的话,会把ery混为一谈吗?

最佳回答

在任何特定网页上不得使用一个以上的元件。 它们用于独特地确定要素。

现在,在你的具体例子中,如果你正在使用 j,那么总是有办法选择你想要的东西,使你们的挑选者掌握更多的信息(div#ID, img#ID)——不会混淆不清,但你应该坚持标准,而不是重复使用。

From the W3c: http://www.w3.org/TR/html4/struct/global.html (html4, but it still applies)

7.5.2 Element identifiers: the id and class attributes

Attribute definitions

id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
class = cdata-list [CS]
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.
问题回答

根据以往的经验:

For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient. When another selector is attached to the id selector, such as h2#pageTitle, jQuery performs an additional check before identifying the element as a match.

Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.

Source: http://api.jquery.com/id-selector/

http://www.w3.org/rel=“nofollow”

这并不是有效的html,ids 必须是独一无二的。

是的,由于 duplicate子的重复, j可能赢得预期的 work。 事实上,我几天前就在这里看到了一个功能破碎的问题。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签