jquery 与 .html() 与 Firefox 的链接颜色问题

发布于 2024-10-05 21:05:18 字数 618 浏览 0 评论 0原文

所以我有这个代码:

<a id="baby" href="#" style="display:inline-block;color:#373529;">
<div id="yea" class="like-num">Yeaaaaaaa</div>
</a>

使用CSS,

a {
 color: #1a5790; 
}

a * {
 color: #1a5790; 
}

.like-num{


color:#373529; 

}

所以这个链接中的链接颜色应该是黑色的,即使默认链接CSS是蓝色的。它有效,链接颜色确实变黑了。

但是然后我调用一个jquery ajax调用,成功后它将用返回的数据替换#yea,所以

$('#yea').html(data);

但是当数据替换完成时,链接颜色变回蓝色,即使之前它是黑色的,这只发生在firefox,不在 ie 或 chrome 中,

有谁知道我如何修改代码,以便即使在替换数据后链接颜色仍保持黑色:

提前致谢!

没有勺子

——黑客帝国

so I have this code:

<a id="baby" href="#" style="display:inline-block;color:#373529;">
<div id="yea" class="like-num">Yeaaaaaaa</div>
</a>

with css

a {
 color: #1a5790; 
}

a * {
 color: #1a5790; 
}

.like-num{


color:#373529; 

}

so the link color in this link is supposed to be blackish even though default link css is blue. And it works, the link color did become blackish.

But then I call a jquery ajax call that on success it would replace #yea with the returned data, so

$('#yea').html(data);

But then when the data replace is completed, the link color turns back into blue even though before it was black, and this only happens in firefox, not in ie or chrome

does anyone know how I can modify the code so that link color stays black even after the data is replaced:

Thanks in advance!

There is no spoon

-The Matrix

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

维持三分热 2024-10-12 21:05:18

内部元素(span)内不能有块元素(div)。这是无效的 HTML。

但是,您可以将 div 更改为 span 并为 span 提供样式 display: block 以将其显示为块元素。这是有效的。

更好的是:您也可以将 display: block 添加到 a 本身。当您这样做时,您不需要 a 中的额外元素,这可能会解决您的问题。

You cannot have a block element (div) inside an inside element (span). This is invalid HTML.

You can however change div to span and provide the span with style display: block to show it as a block element. This is valid.

Even better: you can add display: block to the a itself as well. When you do that, you don't need the extra element inside the a, and this will probably solve your problem.

千秋岁 2024-10-12 21:05:18

将所有“a”和“a.*”CSS 替换为 a, a:visited { color: #1A5790; } 看看它是否仍然如此。

编辑:刚刚注意到 div 标签实际上位于 a 标签内。这将是无效的 HTML(内联元素内的块级元素)。尝试替换

与 <跨度>看看是否有帮助。

Replace all your "a" and "a.*" css with a, a:visited { color: #1A5790; } and see if it still does it.

Edit: Just noticed the div tag is actually inside the a tag. That would be invalid HTML (block-level element inside of an inline-element). Try replacing <div> with <span> and see if that helps.

幽蝶幻影 2024-10-12 21:05:18

它可能是 a * CSS 声明。如果您的返回数据包含元素(例如 span),它将选取该 CSS(颜色 #1a5790),而不是 中的 CSS ;

It's probably the a * CSS declaration. If your return data contains elements (for example a span), it will pick up that CSS (color #1a5790) and not the one in the <a>.

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