html代码如下:
如果要用DOM Core提供的getAttribute方法取得class属性的值,在IE下用getAttribute("class")取值,返回的是null,因为此方法在ie下是无效的,用getAttribute("className")能够正常取到,同意,在ff下用getAttribute("className")取得的结果是null,而用getAttribute("class")能够正确返回结果。
请看下面代码,通过onClick事件弹出一个画面。 文件名为comm.js
<a href="popup.html" class="popup">Example</a>
如果要用DOM Core提供的getAttribute方法取得class属性的值,在IE下用getAttribute("class")取值,返回的是null,因为此方法在ie下是无效的,用getAttribute("className")能够正常取到,同意,在ff下用getAttribute("className")取得的结果是null,而用getAttribute("class")能够正确返回结果。
请看下面代码,通过onClick事件弹出一个画面。 文件名为comm.js
window.onload = prepareLinks;
function prepareLinks(){
var links = document.getElementsByTagName("a");
for(var i=0; i<links.length; i++){
//支持ie浏览器
if (links[i].getAttribute("className")){
if(links[i].getAttribute("className") == "popup") {
links[i].onclick = function(){
popUp(this.getAttribute("href"));
return false;
}
}
} else if(links[i].getAttribute("class")){//支持ff浏览器
if(links[i].getAttribute("class") == "popup") {
links[i].onclick = function(){
popUp(this.getAttribute("href"));
return false;
}
}
}
}
}
function popUp(winURL) {
window.open(winURL,"popup","width=320,height=480");
}