下面就是重点喽,实现自动刷新的js
[JavaScript] 纯文本查看 复制代码 <script>
var timerAutoRefresh;
var autoRefreshCounter;
function setAutoRefresh() {
var $chkAutoRefresh = $( '#chkAutoRefresh' );
if ( $chkAutoRefresh[ 0 ].checked ) {
resetAutoRefreshCounter();
timerAutoRefresh = setInterval( autoRefreshHandle, 1000 );
} else {
clearInterval( timerAutoRefresh );
$chkAutoRefresh.nextAll( 'span:last' ).text( '自动刷新' );
}
}
var autoRefreshCounter;
function autoRefreshHandle() {
if ( 1 > autoRefreshCounter ) {
resetAutoRefreshCounter();
--自动刷新事件,此处为ajax事件,获取刷新的列表内容
pagerOption.pageCallback( pagerOption.currentIndex );
} else {
$( '#chkAutoRefresh' ).nextAll( 'span:last' ).text( autoRefreshCounter + ' 秒后自动刷新' );
autoRefreshCounter--;
}
}
function resetAutoRefreshCounter() {
autoRefreshCounter = 30;
}
</script>
其实很简单的,就是需要逻辑理清就可以实现
|