这很难解释,所以我会尽力而为。
是否可以使用 .remove() 删除重复的 javascript 函数?
功能
function readytouseCard() {
console.log(this);
$('.cardCVV input[name=cvv1]').keyup(function () {
console.log("s");
var checkCVV = $('.cardCVV input[name=cvv1]').filter(function () {
return $.trim(this.value).length < 3;
}).length === 0;
if (checkCVV) {
$("li.checkCode").addClass("checked");
} else {
$("li.checkCode").removeClass("checked");
}
checklistCheck();
});
function checklistCheck() {
var counting = $("li.checked:not(.title)").length;
if (counting == 6) {
console.log(counting);
$("input[name=purchase]").attr("disabled", false);
$("input[name=purchase]").removeClass("purchase-btn-disabled");
$("input[name=purchase]").addClass("purchase-btn");
} else {
$("input[name=purchase]").attr("disabled", true);
$("input[name=purchase]").removeClass("purchase-btn");
$("input[name=purchase]").addClass("purchase-btn-disabled");
}
}
}
主要的
$("li#usercurrentcc").click(function (e) {
e.preventDefault();
var selectedID = $(this).attr("data-id");
var qString = 'selectedID=' + selectedID;
$.post('/assets/inc/get-logged-info-card.php', qString, function (results) {
if ($("#usercurrentccbox, #addnewccbox").length != 0) {
$("#usercurrentccbox, #addnewccbox").fadeOut("fast", function () {
$(this).remove();
$("<div class='creditCardDetails' id='usercurrentccbox'><div class='creditCard'><div class='cardChoice'><span>Choose Card Type</span><input name='cctype1' type='radio' value='V' class='lft-field' id='visa' /><label for='visa'></label><input name='cctype1' type='radio' value='M' class='lft-field' id='mastercard' /><label for='mastercard'></label><input name='cctype1' type='radio' value='A' class='lft-field' id='amex' /><label for='amex'></label></div><!--cardChoice--><div class='cardNumber'><input name='ccn1' id='ccn' type='text' class='long-field' value='" + results[0].maskccn + "' maxlength='19' readonly /></div><div class='cardCVV'><input name='cvv1' id='cvv' type='text' maxlength='5' class='small-field' /></div><div class='creditCardName'><input name='ccname1' id='ccname' type='text' class='long-field' value='" + results[0].ccname + "' readonly/></div><div class='cardDate'><input name='exp11' id='exp1' type='text' maxlength='2' class='small-field' value='" + results[0].ccm + "' readonly /><input name='exp21' id='exp2' type='text' maxlength='4' class='small-field' value='" + results[0].ccy + "' readonly /></div></div><!--creditCard-->").insertAfter("#paymentCardChoice");
$('#usercurrentccbox .cardChoice input#' + results[0].cct + '').attr("checked", true);
$('#usercurrentccbox .cardChoice label').removeClass("active");
$('#usercurrentccbox .cardChoice label[for="' + results[0].cct + '"]').addClass("active");
$("li:not(.title,.checkCode)").addClass("checked");
});
readytouseCard();
} else {
$(".submit-btn").fadeIn();
$("<div class='creditCardDetails' id='usercurrentccbox'><div class='creditCard'><div class='cardChoice'><span>Choose Card Type</span><input name='cctype1' type='radio' value='V' class='lft-field' id='visa' /><label for='visa'></label><input name='cctype1' type='radio' value='M' class='lft-field' id='mastercard' /><label for='mastercard'></label><input name='cctype1' type='radio' value='A' class='lft-field' id='amex' /><label for='amex'></label></div><!--cardChoice--><div class='cardNumber'><input name='ccn1' id='ccn' type='text' class='long-field' value='" + results[0].maskccn + "' maxlength='19' readonly /></div><div class='cardCVV'><input name='cvv1' id='cvv' type='text' maxlength='5' class='small-field' /></div><div class='creditCardName'><input name='ccname1' id='ccname' type='text' class='long-field' value='" + results[0].ccname + "' readonly/></div><div class='cardDate'><input name='exp11' id='exp1' type='text' maxlength='2' class='small-field' value='" + results[0].ccm + "' readonly /><input name='exp21' id='exp2' type='text' maxlength='4' class='small-field' value='" + results[0].ccy + "' readonly /></div></div><!--creditCard-->").insertAfter("#paymentCardChoice");
$('#usercurrentccbox .cardChoice input#' + results[0].cct + '').attr("checked", true);
$('#usercurrentccbox .cardChoice label').removeClass("active");
$('#usercurrentccbox .cardChoice label[for="' + results[0].cct + '"]').addClass("active");
$("li:not(.title,.checkCode)").addClass("checked");
}
readytouseCard();
}, "json");
});
readytouseCard();
该功能在第一次单击时启动并工作,但之后它不再工作。控制台日志只显示Window #,当我再次单击时它显示Window # Window #
所以我希望有一种方法可以使用 .remove(); 杀死函数 readytouseCard();
提前致谢