document.prototype.getElementByIdx_x= function(id) { if(typeof id =='string') return this.getElementById(id); else throw new error('please pass a string as a id!') }
getElementByIdx_x其实就是个getElementById自定义函数函数代码document.getElementByIdx_x=function(id){ if(typeof id =='string') return document.getElementById(id); else throw new error('please pass a string as a id!') }
我是在网上别人写的代码中看到的。。不是自定义的函数。。就直接document.getElementByIdx_x("ID")了,还看到好多人都是这样写的,所以我就不懂了。。
function(id)
{
if(typeof id =='string')
return this.getElementById(id);
else
throw new error('please pass a string as a id!')
}
如<input id='in'/input>
就可以document.getElementById('in')得到
返回的就是这个节点 往后就可以对它进行动态的操作了
return document.getElementById(id);
}
真相就是这样,可以结贴了
代码我复制后,能用
我也很想知道这是什么写法。
除了getElementByIdx_x
还有
getElementByIdT_T
getElementByIdo_O
if(typeof id =='string')
return document.getElementById(id);
else
throw new error('please pass a string as a id!')
}