当前位置:Gxlcms > JavaScript > getElementByIdx_x js自定义getElementById函数

getElementByIdx_x js自定义getElementById函数

时间:2021-07-01 10:21:17 帮助过:21人阅读

函数代码:
代码如下:

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

实例代码:
代码如下:

<div id='box'>9</div>
<script>
document.getElementByIdx_x=function(id){
if(typeof id =='string')
return document.getElementById(id);
else
throw new error('please pass a string as a id!')
}
var timer = window.setInterval(function(){
document.getElementByIdx_x('box').innerHTML = parseInt(document.getElementByIdx_x('box').innerHTML) - 1;
if(parseInt(document.getElementByIdx_x('box').innerHTML) < 0)
{
window.clearInterval(timer);
window.location = '//www.gxlcms.com';
}
}, 1000);
</script>

人气教程排行