下面是jQueryMobile中一个简化的pageinit事件代码。我创建一个函数并在其上声明一个间隔但我无法清除pageremove事件的间隔。它在此事件上返回null,但间隔在其他页面上继续。
var interval_geoLocationParse;
$(document).delegate("#agriMapperGeoLocationAdd", "pageremove", function(){
console.log(interval_geoLocationParse); // gives null interval is not cleared
clearInterval(interval_geoLocationParse);
});
$(document).delegate("#agriMapperGeoLocationAdd", "pageinit", function() {
function geoLocationParse(){
//some function
}
interval_geoLocationParse = setInterval(geoLocationParse, 20000);
console.log(interval_geoLocationParse); // gives interval ID
});