the confirm() was just an idea of some validation that could fail and block the remaining events to happen. The real scenario is that I need to encrypt the credit card data and perform some 3D authorization before the form is submitted OR the place order button is clicked. If the 3D auth or the encryption fails, I need to stop the order of being placed (triggered by the first listener). I cannot modify the other functions or listeners, because they may vary for each store. I was able to do this with jquery, but i m struggling to do with prototypejs.
我有一个地方命令,其中载有一个点击事件,它将执行一些任务,并通过阿加西发布命令。
我愿补充说,将在“<>之前”触发的另一次点击事件,并开展一些行动和验证。
视结果而定:
- I would like to prevent the other events to be triggered
- OR if success, just proceed and call the other click listeners.
然而,我为与PrototypeJS或纯粹的Java一道实现这一目标而努力。
这将是一个简单的例子,但当然,我尝试了许多不同的做法,包括过分严格的活动。
任何想法都受到赞赏。
var button = $( onestepcheckout-place-order-button )
//Original event
button.observe( click , function(e) {
console.log( Order submitted )
})
// New event (I only have access to modify from here onwards)
button.observe( click , function(event) {
if (confirm( Are you sure? ) === false) {
console.log( The order should not be submitted )
event.preventDefault()
event.stopPropagation()
return false
}
// The other events should be triggered (order submitted)
button.fire( click )
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.js"></script>
<button id="onestepcheckout-place-order-button" type="button"><span>Place order</span></button>