js的实例化写法及調用

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')"/>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值