在我的JQuery Mobile項目中,我在主頁上有一個圖像滑塊。通過此頁面輸入時,此工作正常。但是,如果我離開,然後返回到頁面,它不起作用。如何在每次加載頁面時運行代碼
我對每個JQM頁面都有1個html文件(例如4個頁面等於4個html文件)。
下面給出的代碼js通過頁面頭部的引用加載到包含它的js文件中。
$(function() {
//Global variable that stores advertising banners.
var featured = new Array();
//Adds information about the new banners.
featured.push(["http://www.google.co.uk/", "assets/temp/slider/01.jpg", "FEATURED: Cessna CItation XVII"]);
featured.push(["http://www.mashable.com", "assets/temp/slider/02.jpg", "FEATURED: Cessna CItation XVII"]);
featured.push(["http://www.engadget.com", "assets/temp/slider/16.jpg", "FEATURED: Cessna CItation XVII"]);
var featured_element = document.getElementById("slider");
//Prints a new link with image in advertising box.
$.each(featured, function (i, advert) {
featured_element.innerHTML += "<img src=\"" + advert[1] + "\" data-plugin-slide-caption=\"<a href='" + advert[0] + "'>" + advert[2] + "<\/a>\"/>";
});
$("#slider").excoloSlider({
mouseNav: false,
interval: 3500, // = 3.5 seconds
playReverse: true
});
});
我該如何適應這種情況,以便每次加載該給定頁面時都會觸發它?
'window.onpopstate = function(){...};'??? –
爲什麼不使用document.ready()? –
@PratikJoshi因爲它的JQuery Mobile。 –