ajax 中操作this,需要先在ajax的外面給this重新定義為_this!!


//設置為默認收貨地址
$(document).on('tap','.right_none',function(){
    var _this = $(this);                //只有這樣定義,在ajax的內部才可以調用this  
    var id = $(this).data('id');
    api.set_default({
        uid : _user.id,
        id  : id
    },function(data){
        if(data.errno){
            alert(data.errdesc);
            return false;
        }else{
            $('.main_bottom').find('div:first-child').removeClass('right');
            $('.main_bottom').find('div:first-child').addClass('right_none');
            _this.removeClass('right_none');
            _this.addClass('right');              //ajax 中操作this,需要先在ajax的外面給this重新定義為_this!!
        }
    },function(){
        alert("網絡錯誤");
        return false;
    });
});

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM