代码运行但HTML内容未添加到页面

时间:2014-03-30 13:18:36

标签: javascript jquery jquery-mobile

我正在使用'单页模型'在JQuery Mobile上工作。 (例如1页= 1个html文件),需要显示一些广告。但是,在首页打开后,广告不会显示在任何页面上。我添加了一些警报,所以我知道代码正在运行,它只是没有输出到html。

以下是我的JS文件的内容:

$(document).on("pageshow", function () {
alert("LOADED BANNER CODE");
//Global variable that stores advertising banners.
var ads = new Array();

//Function that starts when the page finished loading.

  //Adds information about the new banners.
  ads.push(["http://www.dpbolvw.net/click-7490208-11465196", "http://www.lduhtrp.net/image-7490208-11465196", ""]);
  ads.push(["http://www.anrdoezrs.net/click-7490208-11646171", "http://www.ftjcfx.com/image-7490208-11646171", ""]);
  /*
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  ads.push(["", "", ""]);
  */
  //ads.push(["http://w3schools.com/svg/default.asp", "http://adn.impactradius.com/display-ad/378-10418", "SVG"]);

  //Starting rotation with the first banner.
  ad_rotate(0);

function ad_rotate(active){   
  alert("LOADED BANNER ADROTATE CODE");
  //Gets the div that will display banners.
  var ad_element = document.getElementById("ad");

  //Prints a new link with image in advertising box.
  ad_element.innerHTML = "<a href=\""+ads[active][0]+"\"><img src=\""+ads[active][1]+"\" alt=\""+ads[active][2]+"\" title=\""+ads[active][2]+"\" /></a>";

  //Switches to the next banner.
  active++;

  //If the counter has reached the end, it shall start again from zero.
  if(active >= ads.length){
    active = 0;
  }

  //Run the function in 5000 milliseconds (5 seconds).
  //setTimeout("ad_rotate("+active+")", 5000);
  setTimeout(function () {ad_rotate(active);}, 5000);
};
});

我在每个页面的头部调用它,以确保它始终被加载。该脚本在加载的第一页上运行正常,警报表明脚本正在后续页面上运行。但是,在随后访问的网页上,广告不会出现。

Firebug在控制台中没有显示任何错误,因此该脚本似乎无法找到ID为&#39; ad&#39;或者仍然将广告添加到div中的div在第一页。

知道发生了什么&amp;如何解决?

0 个答案:

没有答案