jquery img 标签在使用追加添加后被删除

发布于 2024-11-19 06:29:03 字数 3986 浏览 2 评论 0原文

在我的网站上,我尝试使用 ("#report-type").append($img) 附加我的图像,其中 img 是一个包含 src 网站的 jquery 对象,基于下拉菜单选择更改 img 的 src。我知道它实际上附加在正确的位置,img 标签的格式正确,并且如果我只是将 img 标签硬编码到 HTML 中,图像就会显示。

然而,发生的情况是页面运行,我在 firebug 中看到该 img 被附加了一瞬间,然后就消失了。有谁知道为什么会发生这种情况?

这是我的下拉更改处理程序的函数:

    $(".update-report").click(function () {
        var src, image, $img2, val;

        //Clear old charts
        //$("#report-type option").children().remove();

        //alert(typeof $("select option:selected").val());

        val = $("select option:selected").val();
        switch (val[0]) {
            case "0":
                src = "https://graphite.admarketplace.net:2222/render/?from=-7days&width=1400&height=420&_salt=1309990757.707&target=alias(movingAverage(divideSeries(sumSeries(*.server.xml.*.revenue)%2CsumSeries(*.server.xml.*.clicks)),200),%22CPC%22)&fgcolor=black&bgcolor=white&title=Average%20CPC%20per%20minute%20-%207%20Days&hideLegend=true";

                $("#chart1").attr('src',src);
                break;

            case "1":
                alert("here1");
                src = "http://graphite.admarketplace.net:2222/render/?from=-30days&width=1400&height=420&_salt=1309990757.707&target=alias(movingAverage(divideSeries(sumSeries(*.server.xml.*.revenue)%2CsumSeries(*.server.xml.*.clicks)),200),%22CPC%22)&fgcolor=black&bgcolor=white&title=Average%20CPC%20per%20minute%20-%2030%20Days&hideLegend=true";
                $img = createImg(src);
                alert(typeof $img);
                $("#report-type").append($img);
                break;

            case "2":
                alert("here2");
                src = "http://graphite.admarketplace.net:2222/render/?from=-1hour&width=1000&height=400&_salt=1309980469.069&target=alias(e.network.lb.xml.AverageRespTime,%22East%22)&target=alias(w.network.lb.xml.AverageRespTime,%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%20Hour";
                $img = createImg(src);
                src = "http://graphite.admarketplace.net:2222/render/?from=-25hour&until=-24hour&width=1000&height=400&_salt=1309980469.069&target=alias(e.network.lb.xml.AverageRespTime,%22East%22)&target=alias(w.network.lb.xml.AverageRespTime,%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%20Hour%20Yesterday";
                $img2 = createImg(src);

                $(".grid 16").append($img);
                $(".grid 16").append($img2);
                break;

            case "3":
                alert("here3");
                src = "http://graphite.admarketplace.net:2222/render/?from=-1day&width=1000&height=400&_salt=1309980469.069&target=alias(movingAverage(e.network.lb.xml.AverageRespTime,20),%22East%22)&target=alias(movingAverage(w.network.lb.xml.AverageRespTime,20),%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%2024%20Hours";
                $img = createImg(src);
                src = "http://graphite.admarketplace.net:2222/render/?from=-2day&until=-1day&width=1000&height=400&_salt=1309980469.069&target=alias(movingAverage(e.network.lb.xml.AverageRespTime,20),%22East%22)&target=alias(movingAverage(w.network.lb.xml.AverageRespTime,20),%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Yesterday";
                $img2 = createImg(src);

                $(".grid 16").append($img);
                $(".grid 16").append($img2);
                break;
                default:
                    alert("in the default");
        }
    });

只需注意这里的情况 0,因为我一直在尝试让它工作。即使我将 img 标签硬编码到 HTML 中并且仅尝试更改 src,这也不起作用。但是,当我尝试附加整个图像时,这也不起作用。

On my website I tried to append my image using ("#report-type").append($img) where img is a jquery object with a src website included, based upon a drop down menu selection changing the src of the img. I know that it actually appends in the right place, the img tag is properly formatted, and that the image shows up if i just hardcode the img tag into the HTML.

however, what happens is the page runs, and I see in firebug that the img is appended for a split second and then it disappears. Does anyone have any idea why this might be happening?

here is my function for the dropdown change handler:

    $(".update-report").click(function () {
        var src, image, $img2, val;

        //Clear old charts
        //$("#report-type option").children().remove();

        //alert(typeof $("select option:selected").val());

        val = $("select option:selected").val();
        switch (val[0]) {
            case "0":
                src = "https://graphite.admarketplace.net:2222/render/?from=-7days&width=1400&height=420&_salt=1309990757.707&target=alias(movingAverage(divideSeries(sumSeries(*.server.xml.*.revenue)%2CsumSeries(*.server.xml.*.clicks)),200),%22CPC%22)&fgcolor=black&bgcolor=white&title=Average%20CPC%20per%20minute%20-%207%20Days&hideLegend=true";

                $("#chart1").attr('src',src);
                break;

            case "1":
                alert("here1");
                src = "http://graphite.admarketplace.net:2222/render/?from=-30days&width=1400&height=420&_salt=1309990757.707&target=alias(movingAverage(divideSeries(sumSeries(*.server.xml.*.revenue)%2CsumSeries(*.server.xml.*.clicks)),200),%22CPC%22)&fgcolor=black&bgcolor=white&title=Average%20CPC%20per%20minute%20-%2030%20Days&hideLegend=true";
                $img = createImg(src);
                alert(typeof $img);
                $("#report-type").append($img);
                break;

            case "2":
                alert("here2");
                src = "http://graphite.admarketplace.net:2222/render/?from=-1hour&width=1000&height=400&_salt=1309980469.069&target=alias(e.network.lb.xml.AverageRespTime,%22East%22)&target=alias(w.network.lb.xml.AverageRespTime,%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%20Hour";
                $img = createImg(src);
                src = "http://graphite.admarketplace.net:2222/render/?from=-25hour&until=-24hour&width=1000&height=400&_salt=1309980469.069&target=alias(e.network.lb.xml.AverageRespTime,%22East%22)&target=alias(w.network.lb.xml.AverageRespTime,%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%20Hour%20Yesterday";
                $img2 = createImg(src);

                $(".grid 16").append($img);
                $(".grid 16").append($img2);
                break;

            case "3":
                alert("here3");
                src = "http://graphite.admarketplace.net:2222/render/?from=-1day&width=1000&height=400&_salt=1309980469.069&target=alias(movingAverage(e.network.lb.xml.AverageRespTime,20),%22East%22)&target=alias(movingAverage(w.network.lb.xml.AverageRespTime,20),%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Current%2024%20Hours";
                $img = createImg(src);
                src = "http://graphite.admarketplace.net:2222/render/?from=-2day&until=-1day&width=1000&height=400&_salt=1309980469.069&target=alias(movingAverage(e.network.lb.xml.AverageRespTime,20),%22East%22)&target=alias(movingAverage(w.network.lb.xml.AverageRespTime,20),%22West%22)&yMax=500&fgcolor=black&bgcolor=white&title=Average%20Response%20Time%20in%20milliseconds%20Yesterday";
                $img2 = createImg(src);

                $(".grid 16").append($img);
                $(".grid 16").append($img2);
                break;
                default:
                    alert("in the default");
        }
    });

Just pay attention to case 0 here because I've been fooling around trying to get this to work. This does not work either, even when I hardcode an img tag into the HTML and ONLY try and change the src. However when I try and append the whole image this doesn't work either.

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

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

发布评论

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

评论(1

云巢 2024-11-26 06:29:03

我怀疑你有某种广告拦截器,它会删除图像,因为 src 是 admarketplace...

我们曾经花了一个晚上来解决“banner.jpg”图像的类似问题:)

I'm suspecting you have some kind of adblocker which removes the image since the src is admarketplace...

We once spent an evening on a similar problem with a "banner.jpg" image :)

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