我有一个包含多个表单的页面,每个单选按钮上都有一个更改侦听器,用于在更改时提交表单。除了提交错误的表单。我浏览了页面上的源代码,没有发现任何不匹配的标签(也许有人知道一个好的html linter以防万一?)。在更改事件期间,单选按钮会影响错误的表单
这是最相关的JS,我有:
var AcceptanceBtns = this.AcceptanceBtns = function (accBtnForm) {
this.acceptanceBtnForm = accBtnForm;
this.labels = this.acceptanceBtnForm.find("label.approval-buttons");
this.radios = this.labels.find("input.radio-btn");
this.checkedRadio = this.radios.filter(':checked');
this.styleCheckedBtn();
}
AcceptanceBtns.prototype.confirmBtns = function() {
var that = this;
this.styleAcceptBtn()
this.radios.on("change", function() {
console.log("going");
var radio = $(this);
var label = radio.parent();
that.styleBtnsOnChange(label)
that.radios.off();
that.acceptanceBtnForm.submit();
});
};
AcceptanceBtns.prototype.startListening = function() {
if (this.acceptanceBtnForm.length === 0) { return; }
this.confirmBtns();
this.submitResponse();
};
var AcceptAffiliateBtns = this.AcceptAffiliateBtns = function (formEl) {
AB.call(this, formEl);
};
AcceptAffiliateBtns.prototype = Object.create(AB.prototype);
AcceptAffiliateBtns.prototype.constructor = AcceptAffiliateBtns;
$(document).on("page:change", function() {
if (typeof aab === 'undefined') {
var aab = {};
} else {
$.each(aab, function (key, val) { val.stopListening(); });
}
$('form.accepting-affiliates').each(function (i, el) {
aab[i.toString()] = new AcceptAffiliateBtns ($(el));
aab[i.toString()].startListening();
});
});
调试时我在on change
事件控制台和that
检查指的是第一种形式,虽然this
的变化范围之外的正确的是(并有一些js的样式,你可以看到,它适用于所有按钮)。因此,无线电通信局正在改变第一种形式,或者变量之间的混淆实例之间
我只看到你在'confirmBtns'中使用'that',并且我看不到'confirmBtns'与'change'事件有什么关系。 –
'confirmBtns'在'startListening'中被调用,我没有包含它来避免混乱,因为一切都被称为ok。 – MCB
如何调用confirmBtns来确定this的值,这非常重要。 –