您的位置:首页 > Web前端 > JavaScript

常用的几段javascript代码分享

2014-03-25 00:00 549 查看
1.3秒后自动返回
<span id="totalSecond">3</span>秒后自动返回 

<script language="javascript" type="text/javascript"> 
<!-- 
var second = document.getElementById('totalSecond').textContent; 
if (navigator.appName.indexOf("Explorer") > -1) //判断是IE浏览器还是Firefox浏览器,采用相应措施取得秒数 
{ 
second = document.getElementById('totalSecond').innerText; 
} else 
{ 
second = document.getElementById('totalSecond').textContent; 
} 
setInterval("redirect()", 1000); //每1秒钟调用redirect()方法一次 
function redirect() 
{ 
if (second < 0) 
{ 
location.href = 'http://www.baidu.com'; 
} else 
{ 
if (navigator.appName.indexOf("Explorer") > -1) 
{ 
document.getElementById('totalSecond').innerText = second--; 
} else 
{ 
document.getElementById('totalSecond').textContent = second--; 
} 
} 
} 
--> 
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: