Home > Web Front-end > JS Tutorial > body text

getElementByIdx_x js自定义getElementById函数_javascript技巧

WBOY
Release: 2016-05-16 17:56:47
Original
1766 people have browsed it

函数代码:

复制代码 代码如下:

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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!