getElementByIdx_x js自定義getElementById函數(shù)
更新時間:2012年01月24日 16:30:45 作者:
最近看JS代碼,發(fā)現(xiàn)不少人問getElementByIdx_x是什么函數(shù),其實就是個getElementById自定義函數(shù)
函數(shù)代碼:
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 = 'http://chabaoo.cn';
}
}, 1000);
</script>
復(fù)制代碼 代碼如下:
document.getElementByIdx_x=function(id){
if(typeof id =='string')
return document.getElementById(id);
else
throw new error('please pass a string as a id!')
}
實例代碼:
復(fù)制代碼 代碼如下:
<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 = 'http://chabaoo.cn';
}
}, 1000);
</script>
您可能感興趣的文章:
- js中document.getElementById(id)的具體用法
- javascript typeof id===''string''?document.getElementById(id):id解釋
- 原生js操作checkbox用document.getElementById實現(xiàn)
- js querySelector和getElementById通過id獲取元素的區(qū)別
- js中document.getElementByid、document.all和document.layers區(qū)分介紹
- JavaScript中也使用$美元符號來代替document.getElementById
- javascript代碼在ie8里報錯 document.getElementById(...) 為空或不是對象的解決方法
- javascript getElementById 使用方法及用法
- js中的getElementById的使用方法
相關(guān)文章
JS?Angular?服務(wù)器端渲染應(yīng)用設(shè)置渲染超時時間???????
這篇文章主要介紹了JS?Angular服務(wù)器端渲染應(yīng)用設(shè)置渲染超時時間,???????通過setTimeout模擬一個需要5秒鐘才能完成調(diào)用的API展開詳情,需要的小伙伴可以參考一下2022-06-06javascript prototype的深度探索不是原型繼承那么簡單
JavaScript中對象的prototype屬性,可以返回對象類型原型的引用。這是一個相當(dāng)拗口的解釋,要理解它,先要正確理解對象類型(Type)以及原型(prototype)的概念。2008-06-06