0

我有这个代码,它只是在我点击提交后禁用我页面上的所有提交按钮和所有 AJAX 链接。我克隆了单击的事件,以便服务器端我知道按下了什么提交。这在 IE 和 Firefox 上完美运行,但在 chrome 上它拒绝提交任何东西。似乎它阻止了提交,因为我看到克隆已正确插入 DOM 并且控制台中没有记录任何错误。

// 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 );

因为如果我评论说它也适用于 chrome。我正在使用 jQuery 1.6(但它是一个 wordpress 插件,因此版本可能会有所不同)

有谁知道出了什么问题?

4

2 回答 2

2

当您的按钮被禁用时,表单未提交添加一个 setTimeOut 来更改胎面,我会像这样工作

 setTimeout(function() {
$( '#facebook input[type=submit]' ).attr( 'disabled', true );

},0);

它甚至可以使用 0 作为超时时间

于 2012-05-28T17:46:27.497 回答
0

没有看到 HTML 很难说。你可能想弄乱选择器。您可以尝试多种方法:

  $("#facebook [type=submit]").attr('disabled',true);

甚至

  $("[type=submit]").attr('disabled',true);

因为也许您将其作为 a<button>而不是<input>?

  $("#facebook button[type=submit]").attr('disabled',true);
于 2012-05-28T17:21:44.080 回答