一起学习网 一起学习网


JavaScript中也使用$美元符号来代替document.getElementById

网络编程 JavaScript中也使用$美元符号来代替document.getElementById 06-22

function $(id){return document.getElementById(id);

上面的对于新版本的浏览器都是没有问题的,如果使用古老的浏览器,可以使用下面的函数

function $(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId);
}
else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
}
else {
return false;
}
}

来实现$代替document.getElementById的效果,虽然简单,但对于没有引用了prototype和jquery等框架的,避免了每次写document.getElementById,只需在一个公共JavaScript文件定义后便可处处使用了。

JavaScript 内置对象属性及方法集合
1.Date属性(1):constructor所建立对象的函数参考prototype能够为对象加入的属性和方法方法(43):getDay()返回一周中的第几天(0-6)getYear()返回年份.2000年以前为2位,2

JavaScript对象、属性、事件手册集合方便查询
windows对象每个HTML文档的顶层对象.属性frames[]子桢数组.每个子桢数组按源文档中定义的顺序存放.feames.length子桢个数.self当前窗口.parent父窗口(当前窗口

JavaScript 递增、递减运算符实例
递增、递减运算符[Ctrl+A全选注:如需引入外部Js需刷新才能执行]


编辑:一起学习网

标签:对象,属性,窗口,数组,方法