我有這段代碼,它可以簡單地禁用我點擊提交後在頁面上提交的所有按鈕和alla AJAX鏈接。我克隆點擊的事件,以便服務器端我知道什麼提交已被按下。這適用於IE和Firefox,但在Chrome上拒絕提交任何內容。它似乎阻止提交,因爲我發現克隆已正確插入到DOM中,並且在控制檯中沒有記錄任何錯誤。這段代碼阻止我的表單提交(僅適用於chrome,適用於IE和Firefox)
// Block all other submit and ajax requests. The subscribe users burron is avoided because it handles this by itself
$('input[type=submit]').not('#ai1ec_subscribe_users').click(function() {
block_all_submit_and_ajax(this);
});
// Disables all submit buttons after a submit button is pressed.
var block_all_submit_and_ajax = function(el) {
// Clone the clicked button, we need to know what button has been clicked so that we can react accordingly
var $clone = $(el).clone();
// Change the type to hidden
$clone.attr('type', 'hidden');
// Put the hidden button in the DOM
$(el).after($clone);
// Disable all submit button.
$('#facebook input[type=submit]').attr('disabled', true);
// unbind all click handler from ajax
$('#facebook a.btn').unbind("click");
// Disable all AJAX buttons.
$('#facebook a.btn').click(function(e) {
e.preventDefault();
e.stopImmediatePropagation();
});
}
編輯顯然問題出在線路
$('#facebook input[type=submit]').attr('disabled', true);
,因爲如果我評論說,它的工作原理也鑲邊。我使用jQuery 1.6(但它是一個wordpress插件,因此版本可能會有所不同)
任何人都知道什麼是錯的?
您的瀏覽器將發送按下提交的表單按鈕的名稱/值對。您可以簡單地使用它來告訴服務器哪個按鈕被提交。你不需要依靠JavaScript來做到這一點。 –
你可以提供html嗎? –