jquery 在 IE 中找不到图像

发布于 2024-11-03 00:41:34 字数 1567 浏览 1 评论 0原文

已回答

我有一段 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 技术交流群。

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

发布评论

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

评论(1

街道布景 2024-11-10 00:41:34

= 之前添加了 *,现在似乎运行良好:

$(".imghead img[src*='/img/mh_image.jpg']").each(function() {
        $(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
         });

Added a * before the = and it seems to be running fine now:

$(".imghead img[src*='/img/mh_image.jpg']").each(function() {
        $(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
         });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文