jquery 与 .html() 与 Firefox 的链接颜色问题
所以我有这个代码:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
内部元素(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 thea
itself as well. When you do that, you don't need the extra element inside thea
, and this will probably solve your problem.将所有“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.
它可能是
a *
CSS 声明。如果您的返回数据包含元素(例如span
),它将选取该 CSS(颜色#1a5790
),而不是中的 CSS ;
。It's probably the
a *
CSS declaration. If your return data contains elements (for example aspan
), it will pick up that CSS (color#1a5790
) and not the one in the<a>
.