jQuery prepend() 错误?

发布于 2024-09-07 17:34:04 字数 430 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

记忆消瘦 2024-09-14 17:34:04

你不能在锚点内有锚点……所以它不是“有问题的”,它在无效的 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 and http://google.com.

三五鸿雁 2024-09-14 17:34:04

据我所知,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.

枉心 2024-09-14 17:34:04

您必须以正确的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文