閱讀this question's answer暫停click事件,直至用戶輸入
後,我想知道如何構建的preventDefault/stopPropagation取決於用戶點擊的事件,例如:
<html>
<a data-handler="add_to_cart" data-item_id="5">Click</a>
</html>
點擊元素當前調用後端(通過ajax)將項目5添加到用戶手推車。但是,如果我想注入一個對話框第一(只有JavaScript)
var template = '' +
'<div class="dialog">' +
'<p>Really add this item?</p>' +
'<button>Yes</button>' +
'<button>No</button>' +
'</div>'
$(a).click(function(){
# open the dialog template
# if the correct button is clicked continue the default event
});
我不想使用confirm
或prompt
什麼,我基本上是在尋找一種方式用自己的HTML對話框來實現其功能。
您應該使用'confirm',它是跨瀏覽器,可訪問的,並且可以在任何地方工作,包括移動設備。 – meagar 2013-04-29 13:36:23