作者:许琼博762375 | 来源:互联网 | 2023-10-09 20:07
Iamworkingontopofexistingjavascript(thatIcannotalter)andneedtochecksomethingonsub
I am working on top of existing Javascript (that I can not alter) and need to check something on submit.
我正在处理现有的Javascript(我无法改变),需要检查提交的内容。
If my condition is true, no other submit handlers should be applied.
如果我的条件为真,则不应该应用其他提交处理程序。
If my condition is false, all other submit handlers shall be applied.
如果我的条件为假,则应适用所有其他提交处理程序。
What I have tried so far:
到目前为止我尝试了什么:
var form = jQuery('form'),
that = this,
events = $._data(form[0]).events['submit'];
form.off('submit');
form.on('submit', function (event) {
if (that.myCondition()) {
event.preventDefault();
event.stopPropagation();
return false;
} else {
console.log('Call these: ', events);
}
});
Now events
is always empty at that point.
现在,事件总是空着的。
It is empty as soon as I call form.off('submit')
and I didn't get it to work with deep cloning either.
一旦我调用form.off('submit')它就是空的,我也没有让它与深度克隆一起工作。
Update: In this jsfiddle you see that both events are fired. I want one (preferably one that i add LAST) to be fired and prevent the other one from firing.
更新:在这个jsfiddle中你会看到两个事件都被触发了。我想要一个(最好是我加上LAST的一个)被射击并阻止另一个射击。
2 个解决方案