函数代码:
复制代码 代码如下:
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.jb51.net';
}
}, 1000);
</script>
您可能感兴趣的文章:
- 原生js操作checkbox用document.getElementById实现
- 一行代码告别document.getElementById
- js querySelector和getElementById通过id获取元素的区别
- document.getElementById介绍
- document.getElementById方法在Firefox与IE中的区别
- document.getElementById为空或不是对象的解决方法
- getElementByID、createElement、appendChild几个DHTML元素
- document.getElementById获取控件对象为空的解决方法