這篇文章主要介紹了常用的幾段javascript代碼,需要的朋友可以參考下
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>