-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjavascript-gist
More file actions
54 lines (45 loc) · 1.42 KB
/
javascript-gist
File metadata and controls
54 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var clearTimer;
/**
* 设置计时器,
* duration:计时时间
* display: 元素对象
*/
function startTimer(duration, display) {
if( clearTimer!==false ) return;
var timer = duration, minutes, seconds;
clearTimer = setInterval(function () {
if (--timer <= 0) {
clearInterval(clearTimer);
clearTimer=false;
return;
// timer = duration;
}
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.addClass("disabled");
display.attr("disabled", true);
display.css({"background":"#CCCCCC"});
display.text("(" + seconds + ")");
}, 1000);
}
//--------------------------------------------------------
//thinkphp jump
<p class="jump">
页面自动 <a id="href" href="<?php echo($jumpUrl); ?>">跳转</a> 等待时间: <b id="wait"><?php echo($waitSecond); ?></b>
</p>
(function(){
var wait = document.getElementById('wait'),href = document.getElementById('href').href;
var interval = setInterval(function(){
var time = --wait.innerHTML;
if(time == 0) {
location.href = href;
clearInterval(interval);
};
}, 1000);
})();
//----------------------------------------
//javascript trim
txt.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,'');
//@link http://stackoverflow.com/a/498995/1969039