比如定義一個(gè)函數(shù)的兩種調(diào)用方法:
復(fù)制代碼 代碼如下:
function getInfo() {
var info = {
message: "message"
};
return info;
}
復(fù)制代碼 代碼如下:
function $(domId) {
var dom = document.getElementById(domId);
return dom;
}
window.onload = function() {
var dom1 = new $("domId");
var dom2 = $("domId");
alert(dom1 == dom2);
}
復(fù)制代碼 代碼如下:
if (window.XMLHttpRequest === undefined) {
window.XMLHttpRequest = function() {
try {
//如果可用,則使用ActiveX對(duì)象最新的版本
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
} catch (ex1) {
try {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
} catch (ex2) {
throw new Error("XMLHttpRequest is not supported")
}
}
}
}
新聞熱點(diǎn)
疑難解答
圖片精選