2012-02-16 42 views
0

請考慮此代碼。文件就緒代碼運行不止一次

單擊按鈕時,將「活動」類添加到此,並移除所有其他按鈕。

我希望頁面加載一個按鈕設置與積極的類,但是當我把代碼放在(文檔).ready在頂部,每運行一次按鈕被點擊,(它應該被刪除的第二個另一個按鈕被點擊

$(document).ready(function() { 
    $("#society-buttons-form .big-button :input").addClass('active'); 
}); 


    //new jquery for buttons, does not lose class 
    $("#society-buttons-form .small-button :input, #society-buttons-form .big-button :input").hover(function(){ 
     $(this).addClass("hoveractive"); 
     }, 
     function() { 
     $(this).removeClass("hoveractive"); 
     } 
    ); 


    $("#society-buttons-form .small-button :input, #society-buttons-form .big-button :input").click(function(){ 

     $("#society-buttons-form .small-button :input, #society-buttons-form .big-button :input").removeClass('active'); 
     $("#society-buttons-form :input, #society-buttons-form .big-button :input").removeClass('active'); 
     // $("#society-buttons-form .big-button :input").removeClass('active'); 
     $(this).addClass('active'); 
     $(this).removeClass("hoveractive"); 

    }); 
+0

那些懶惰的選擇器是什麼? – elclanrs 2012-02-16 23:46:03

+0

它需要強光兩種按鈕,頂部的一個大按鈕和小按鈕 – 2012-02-16 23:48:23

回答

0

如果按鈕提交形成必須添加

返回假;

您的onclick處理程序結束

+0

它不提交表格,我試過了。 – 2012-02-16 23:52:46