2012-07-07 24 views
1

我用spin.js和jquery.spin插件顯示ajax提交項目在我的web應用程序中的旋轉圖標。jquery旋不替換提交按鈕的形式

它適用於常規鏈接按鈕。然而,對於提交按鈕,它不顯示,我不明白爲什麼。

下面是代碼:

形式:

=form_for(@resource, :url => add_comment_resource_path, :remote => true) do |f| 
       =text_area_tag :comment,nil, :class => "span7", :rows => 3 
       =f.submit "Add Comment", :class => "btn authorize spin" 

JS:

//= require spin.min 
//= require jquery.spin 




    $('.spin').live('click',function(){ 
     $(this).spin('small'); 
    }); 

當我點擊提交按鈕紡紗圖標應該顯示。我可以在下面被插入到HTML頁面上看到:

<input class="btn btn-small authorize spin" name="commit" type="submit" value="Add Comment"> 
    <div class="spinner" style="position: relative; z-index: 2000000000; left: 537px; top: 950px; " aria-role="progressbar"></input> 

似乎被嵌套在輸入這就是爲什麼它沒有顯示內旋轉的圖標。我怎樣才能讓它顯示呢?

回答

1

有一個錯字,改變這種:

$('.spin').live('click',function(){ 

到:

$('.spinner').on('click',function(e){ // you can use `on()` instead of `live()` which is deprecated 
    e.preventDefault() 
+0

的.spin工作正常的應用程序的其他部分,改變了切換時,它什麼都不微調器。它似乎不會出於某種原因在提交按鈕上顯示。 – chell 2012-07-10 10:57:45

+0

@chell嘗試'event.preventDefault()',它可以防止元素的默認操作。 – undefined 2012-07-10 11:30:40