我需要用戶確認他想在打開fancybox創建新遊戲之前結束當前操作。打開fancybox之前需要確認
我已經從試圖阻止onClick事件傳播: How to stop event propagation with inline onclick attribute?
<a href="../Dialogs/CreateGameDialog.aspx" class="createGameLink showDialog" onclick=" if(!confirm('<%# Strings.LoggedIn_ComfirmStartNewGame %>')){ disabledEventPropagation(arguments[0]); return false;} return true;">
<script type="text/javascript">
function disabledEventPropagation(event) {
if (event.stopPropagation) {
event.stopPropagation();
}
else if (window.event) {
window.event.cancelBubble = true;
}
}
</script>
並試圖基於確認結果,以解除綁定/綁定的fancybox: Unbinding Fancybox on thumbnail fade
<a href="../Dialogs/CreateGameDialog.aspx" class="createGameLink showDialog" onclick=" if(!confirm('<%# Strings.LoggedIn_ComfirmStartNewGame %>')){ $('.createGameLink.showDialog').unbind('click.fb'); return false;} else{ bindCreateGameDialog(); return true;}">
<script type="text/javascript">
$('.createGameLink.showDialog').setFancybox({ 'height': 400, 'width': 200 });
</script>
setFancybox是$.fn.fancybox
渦卷。
但是沒有一種方法奏效。
謝謝它的作品。但爲什麼它停止onClick事件傳播的工作呢? –