我已经在(function() {} })()
内封闭了一个脚本以隔离它,从而避免与页面上的其他脚本发生任何冲突,但是该脚本不再起作用。请问我在哪里错了?
页面在不同的标签中包含多个Javascript脚本。我想将这些脚本组合成一个或两个标签。我想隔离这些脚本以避免将来发生冲突。
var myofferexpiration = (function() { // I enter this or
// (function() {
var min = 20; /* Set the minutes start range time. */
var max = 15;
var random = Math.floor(Math.random() * (max - min)) + min;
var sec = 04;
var min = random;
var hour = 00; /* Set the countdown start time (hh.mm.ss). */
var speeddata = 1000; // velocità conteggio 1000 = 1ss
var time0, time1;
var settime = 1000; // 103300 = 10 hour 33 min 00ss | 500 = 5 minuti | 1000 = 10 minuti
var delay=0;
var duringtime = 1000; // 100 = 100ss | 1000 = 1000ss (al termine rinizia da capo)
time1 = (hour *10000 + min * 100 + parseInt(sec)).toString();
console.log("time1", time1);
function refresh() {
time0 = localStorage.getItem("offerexpi_99");
if (time0) {
hour = Math.floor(parseInt(time0) / 10000);
var hour05 = parseInt(time0) - hour * 10000;
var min = Math.floor(hour05 / 100);
sec = hour05 - min * 100;
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec <= 9) {
sec = "0" + sec;
}
if (min == -01) {
min = 59;
hour = hour - 1;
} else {
hour = hour;
}
if (document.getElementById) {
hour1.innerHTML = (hour <= 9 ? "0" + hour : hour);
min1.innerHTML = (min <= 9 ? "0" + min : min);
sec1.innerHTML = sec;
}
time0 = hour * 10000 + min * 100 + parseInt(sec);
if (time0 < 1) {
time0 = settime;
}
delay++;
if (delay > duringtime) {
delay = 0;
time0 = time1;
}
localStorage.setItem("offerexpi_99", time0);
inter = setTimeout("refresh()", speeddata);
if (hour == '00' && min == '00' && sec == '00') {
sec = "00";
}
} else {
time0 = time1;
localStorage.setItem("offerexpi_99", time0);
setTimeout("refresh()", speeddata);
}
}
refresh();
})(); // I entered this