2017-04-05 74 views
0

有人可以解釋我請,請問這個按鈕jQuery選擇失敗

<button id="opener" class="ignoreRedirectionAlert">@Resources.Localization.add_record</button> 

可以觸發這個功能:

$(":submit, :radio, .link_button, #ShowAll,#ShowActive").on("click", function() { 
    submitClicked = true; 
}); 

而且,我曾嘗試在選擇加入button:not('.ignoreRedirectionAlert') - 同樣的結果,沒有理由這個按鈕觸發這個功能。

+0

請閱讀[如何創建最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve),然後更新您的問題。 –

回答

1

BUTTON的默認行爲是submit,因此使用:submit選擇器附加事件。

爲了排除使用

:submit:not(.ignoreRedirectionAlert) 

OR

<button type="button" id="opener" class="ignoreRedirectionAlert">@Resources.Localization.add_record</button> 
+0

@rainbowShiningUnicorn請參閱https://api.jquery.com/submit-selector/「請注意,某些瀏覽器將'

0

它的:submit選擇器相匹配,如由默認一個<button>元件是type="submit",除非另有規定。

要讓選擇器避開此元素,請使用:submit:not(.ignoreRedirectionAlert)或將type="button"添加到HTML中的元素。您需要的具體取決於您是否期望按鈕提交其父項form元素。