Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#7726 closed bug (invalid)

":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”选择符,也不会出现这个问题。

Change History (4)

comment:1 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

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

comment:2 Changed 9 years ago by jitter

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

comment:3 in reply to:  1 Changed 9 years ago by leetomer@…

Replying to 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 />)."- http://www.w3.org/TR/xhtml1/#guidelines

comment:4 Changed 8 years ago by dmethvin

Keywords: jqueries added
Note: See TracTickets for help on using tickets.