function Cart() { function el(id) { return document.getElementById(id); }; //將字符串拼接 function string() { var list = new Array(); for(var i=0; i<arguments.length; i++) { list.push(arguments[i]) } return list.join(""); }; var _this = this; //init方法 Cart.prototype.Init = function() { try { if (el("hd_scrollY").value != "") { window.scrollTo(0, Number(el("hd_scrollY").value)); } }catch(e) {}; //窗體滾動事件 window.onscroll = function(e) {e = window.event || e; _this.body_onscroll(e);}; }; // body_onscroll方法 Cart.prototype.body_onscroll = function(e) { var obj = e.srcElement || e.target; el("hd_scrollY").value = qp_shared.getDocumentScrollTop(); }; // btnupdate_onmouseover方法 Cart.prototype.btnupdate_onmouseover = function(id) { var obj = el(id); if (obj != null) obj.className = "btnupdate_hover"; }; Cart.prototype.btnupdate_onmouseout = function(id) { var obj = el(id); if (obj != null) obj.className = "btnupdate_visited"; }; .... Cart.prototype.removeToFavorites = function(id) { if (window.confirm("Are you sure you want to remove from the cart to favorites?")) { oLayer.dw_render(); window.document.location = string("./cart_remove.aspx?type=f&id=", id); } }; } //實例化 var oCart = new Cart(); //在頁面中進行調用 1.引用 2.(實例化對象.方法) <a href="javascript:oCart.removeToFavorites ('fi_225')"/>