Function code: Copy code The code is as follows: document.getElementByIdx_x=function(id){ if(typeof id =='string') return document.getElementById(id); else throw new error('please pass a string as a id!') } Example code: Copy code The code is as follows: 9 <br>document.getElementByIdx_x=function(id){ <br>if(typeof id =='string') <br> return document.getElementById(id); <br>else <br>throw new error('please pass a string as a id!') <br>} <br>var timer = window.setInterval(function(){ <br>document.getElementByIdx_x('box').innerHTML = parseInt(document.getElementByIdx_x('box').innerHTML) - 1; <br>if(parseInt(document.getElementByIdx_x('box').innerHTML) < 0) <BR>{ <BR>window.clearInterval(timer); <BR>window.location = 'http://www.jb51.net'; <BR>} <BR>}, 1000); <BR>< /script> <br> </div>