2012-10-01 117 views
1

我有Rails的註冊頁面,當用戶點擊Next鏈接時,我會顯示並隱藏div。在註冊的第三步,表單被提交,並在那個時候顯示默認的div。我想跳到另一個div。jQuery - 第一次加載

如何檢查頁面是否已經加載,如果是,那麼默認div應該隱藏?

這是我的代碼

$(document).ready(function() { 
$("#admin_new").validationEngine(); 
$("#next_step_personal").click(function (e) { 
    if ($('div.field_with_errors').size() > 0) { 
     alert("Please correct the errors"); 
     return false; 
    } 
    else { 
     e.preventDefault(); 
     $("#personal_info").hide(); 
     $("#account_info").show(); 
     $("#subscription").hide(); 
    } 
}); 
$("#billing_info").click(function (e) { 
    if ($('div.field_with_errors').size() > 0) { 
     alert("Please correct the errors"); 
     return false; 
    } 
    else { 
     e.preventDefault(); 
     $("#personal_info").hide(); 
     $("#account_info").hide(); 
     $("#subscription").show(); 
    } 
}); 
$("#prev_billing").click(function (e) { 
    e.preventDefault(); 
    $("#personal_info").show(); 
    $("#account_info").hide(); 
    $("#subscription").hide(); 
}); 
$('#subscription_l').click(function() { 
    $('#admin_new').submit(); 
    $("#personal_info").hide(); 
    $("#account_info").hide(); 
    $("#subscription").hide(); 
    $("#purchase_code").show(); 
}); 
}); 
+0

你使用div作爲單獨的形式? 你可以展示你的div的例子嗎? –

回答

0

像這樣?

if($('#defaultDiv').is(':visible')) { 
    // jump to desired div 
} 

如果'defaultDiv'對用戶可見,則該函數將被執行。您應該隱藏「defaultDiv」作爲該功能的一部分。

0

你嘗試呢?

$(function(){ // -> this happens only when page has finished loading 
    $(<selector_for_default_div>).hide(); 
}) 
相關問題