1.对于js中onclick方法的使用写法,正确如下:
getChoice = function (param_index) {
$(".charge-btn-group").removeClass("btn-active");
$("#charge-btn-group" + param_index).addClass("btn-active");
};
错误如下:
getChoice: function (param_index) {
$(".charge-btn-group").removeClass("btn-active");
$("#charge-btn-group" + param_index).addClass("btn-active");
},
2.在onclick方法的调用内,采用self
a.html
for(var a = 0; a < this.chargeList.length; a++){
$("#charge-group").append(
'<div class="charge-btn-group" id="charge-btn-group'+a+'" onclick="getChoice('+a+')">'+
' <div class="charge-times">上机<span id="times-num'+a+'"></span>次</div>'+
' <div class="charge-money">(扣除<span id="money-num'+a+'">3</span>门店币)</div>'+
'</div>'
);
$("#times-num"+a).html(this.chargeList[a].times);
$("#money-num"+a).html(this.chargeList[a].times * this.machineList.money);
}
b.js
Pay.prototype ={
constructor: Pay,
init: function () {
this.bindAction();
return this;
},
bindAction: function () {
var that = this;
this.$confirmPay.click(function () {
self.arousePay();
});
}
}