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

时间:2011-07-11 17:34:04

标签: jquery append image

在我的网站上,我尝试使用(“#report-type”)附加我的图像。附加($ img)其中img是一个包含src网站的jquery对象,基于下拉菜单选择更改src img。我知道它实际上附加在正确的位置,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。但是,当我尝试附加整个图像时,这也不起作用。

1 个答案:

答案 0 :(得分:1)

我怀疑你有某种广告拦截器可以删除图片,因为src是admarketplace ...

我们曾经用“banner.jpg”图片在一个类似的问题上度过了一个晚上:)