Home  >  Article  >  Web Front-end  >  getElementByIdx_x js自定义getElementById函数_javascript技巧

getElementByIdx_x js自定义getElementById函数_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:56:471768browse

函数代码:

复制代码 代码如下:

document.getElementByIdx_x=function(id){
if(typeof id =='string')
return document.getElementById(id);
else
throw new error('please pass a string as a id!')
}

实例代码:
复制代码 代码如下:

9

<script> <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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn