Side navigation
#7726 closed bug (invalid)
Opened December 08, 2010 11:24AM UTC
Closed December 08, 2010 06:58PM UTC
Last modified March 13, 2012 07:37PM UTC
":input“选择符在IE下对相关标签解释不正确
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.6 |
Component: | unfiled | Version: | 1.4.4 |
Keywords: | jqueries | Cc: | |
Blocked by: | Blocking: |
Description
在IE下,如果网页中只存在一个input元素,对于以下三种写法,var n = $(":input").length 得到的结果不同:
1) <input type="text">,即不关闭input元素,这时n=1,结果正确;
2) <input type="text" />,即使用"/>"关闭空标签,这时n=1,结果也正确;
3) <input type="text"></input>,即使用结束标签关闭该元素(虽然HTML中input元素没有结束标签,但XHTML貌似允许使用这种写法),则结果发生了错误:n=2。后来经过大量测试发现,在IE下jQuery将结束标记"</input>"也当成一个input元素选取出来了。
但是,在火狐下则不存在这样的问题。另外如果使用的是“input”选择符,也不会出现这个问题。
Attachments (0)
Change History (4)
Changed December 08, 2010 06:58PM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
Changed December 08, 2010 07:17PM UTC by comment:2
Baah.. dmethvin answered while I was typing. Posting anyway..
What you reported isn't a bug in jQuery. The construct <input type="text"></input>
is invalid HTML. Check the link dmethvin provided.
As the html string you pass to jQuery is invalid it depends on the browser what you end up getting. This problem is documented on the jQuery documentation please carefully read the section "Creating New Elements" on the jQuery() api page
Changed December 09, 2010 08:25AM UTC by comment:3
Replying to [comment:1 dmethvin]:
http://jsfiddle.net/dmethvin/kSPwS/ これはバグではありません > "Void elements only have a start tag; end tags must not be specified for void elements." - http://www.w3.org/TR/html-markup/spec.html#void-element
Thanks for your comment。However, I knew that "Void elements only have a start tag; end tags must not be specified for void elements." in HTML specification, but please note that what I said is under XHTML.
"All elements other than those declared in the DTD as EMPTY must have an end tag. Elements that are declared in the DTD as EMPTY ''can have an end tag'' or can ''use empty element shorthand'' (see Empty Elements)"-
http://www.w3.org/TR/xhtml1/#diffs
Though HTML Compatibility Guidelines also says: for the compatibility you had better "use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents", "Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />)."-
Changed October 04, 2011 02:47AM UTC by comment:4
keywords: | → jqueries |
---|
http://jsfiddle.net/dmethvin/kSPwS/
これはバグではありません