jQuery prepend() 错误?
我正在使用 prepend() ,结果似乎有问题。
$('#element').prepend('<div><a href="http://google.com"><a href="http://test.com">Test.com</a> - A site</a></div>');
html 结果(也用 Firebug 查看)有问题:(
<div>
<a href="http://google.com"></a>
<a href="http://test.com">Test.com</a> - A site
</div>
链接只是示例链接)
I'm using prepend() and the result seems to be buggy.
$('#element').prepend('<div><a href="http://google.com"><a href="http://test.com">Test.com</a> - A site</a></div>');
And the html result (also viewed with Firebug) is buggy:
<div>
<a href="http://google.com"></a>
<a href="http://test.com">Test.com</a> - A site
</div>
(The links are just example links)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你不能在锚点内有锚点……所以它不是“有问题的”,它在无效的 HTML 中表现出意外,但是当 HTML 无效时,这是……嗯,预期的。
想想看,如果你点击了内部锚点,你的浏览器应该去哪里?您点击了
http://test.com
和http://google.com
。You can't have an anchor inside an anchor...so it's not "buggy", it's behaving unexpectedly with invalid HTML, but when HTML is invalid that's...well, expected.
Think about it this way, if you clicked on the inside anchor, where should your browser go? You clicked on
http://test.com
andhttp://google.com
.据我所知,html 中不允许嵌套链接(a 元素)。所以浏览器先关闭,然后再关闭。它与 jQUery 没有任何连接。
As I know, nested links (the a elements) are not allowed in html. So browser closes first before the second. It has no connection to jQUery.
嵌套锚标记也有问题。
Nesting anchor tags is also buggy.
您必须以正确的 DOM 格式编写。同意尼克·克拉弗的观点。
一旦“a”标签遇到另一个元素“a”,DOM 就会自动关闭前一个“a”标签。与 xml 相同。
You must write in a proper DOM format. Agreed with Nick Craver.
As soon as "a" tag meet another element "a", DOM automatically closes the previous "a" tag. same as with xml do.