首页 >web前端 >js教程 >getElementByIdx_x js自定义getElementById函数_javascript技巧

getElementByIdx_x js自定义getElementById函数_javascript技巧

WBOY
WBOY原创
2016-05-16 17:56:471845浏览

函数代码:

复制代码 代码如下:

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>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn