jquery 在 IE 中找不到图像
已回答
我有一段 jquery 代码可以在 FF 中运行,但不能在 IE 中运行。令我更加困惑的是,一段几乎相同的代码在两者中都适用。
我有一个带有 imghead 和 imghead2 类的 div
。根据第一个 img
标签的 src,我想附加一段代码
此代码适用于两种浏览器:
$(".imghead2 img[src=/img/image.gif]").each(function() {
$(".imghead2").prepend('<a href="#"><img src="/img/image" border="0" id="anniversary" alt="" /></a>');
});
此代码仅适用于 FF
$(".imghead img[src=/img/mh_image.jpg]").each(function() {
$(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
});
据我所知,这些片段是相同的 - 我实际上只是粘贴了工作片段并将 imghead2
更改为 imghead
。另外,如果我删除 $(".imghead img[src=/img/mh_image.jpg]").each(function() {
它会正确前置。
编辑: 这是 HTML:
<div id="header">
<div class="imghead2" style="float:right"><img src="/img/image.gif" alt="" width="314" height="11" border="0" /></div>
<div class="imghead" style="float:left"><a href="/"><img src="/img/mh_image.jpg" alt="" width="260" height="60" border="0" /></a><noscript><p class="noScriptHead">This page uses Javascript. Your browser either doesn't support Javascript or you have it turned off.<br />To see this page as it is meant to appear please use a Javascript enabled browser.</p></noscript></div>
</div>
Answered
I have a piece of jquery code that works in FF but not in IE. Adding to my confusion is that an almost identical piece of code works in both.
I have a div
with class of imghead and imghead2. Depending on the src of the first img
tag I want to append a piece of code
This code works in both browsers:
$(".imghead2 img[src=/img/image.gif]").each(function() {
$(".imghead2").prepend('<a href="#"><img src="/img/image" border="0" id="anniversary" alt="" /></a>');
});
This Code only works in FF
$(".imghead img[src=/img/mh_image.jpg]").each(function() {
$(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
});
As far as I can see these snippets are identical - I actually just pasted the working one and changed the imghead2
to imghead
. In addition if I remove the $(".imghead img[src=/img/mh_image.jpg]").each(function() {
It prepends properly.
Edit:
Here is the html:
<div id="header">
<div class="imghead2" style="float:right"><img src="/img/image.gif" alt="" width="314" height="11" border="0" /></div>
<div class="imghead" style="float:left"><a href="/"><img src="/img/mh_image.jpg" alt="" width="260" height="60" border="0" /></a><noscript><p class="noScriptHead">This page uses Javascript. Your browser either doesn't support Javascript or you have it turned off.<br />To see this page as it is meant to appear please use a Javascript enabled browser.</p></noscript></div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
=
之前添加了 *,现在似乎运行良好:Added a * before the
=
and it seems to be running fine now: