2011-06-06 21 views
1
$(document).ready(function(){ 
    $("#CO_createAccount").click(function(){ 
     if(this.checked){ 
      $(".CO_accountForm").show(); 
     } else { 
      $(".CO_accountForm").hide(); 
     } 
    }); 
}); 

我將「.CO_accountForm」的css設置爲「display:none;」如果javascript關閉,使顯示/隱藏可訪問

但是,我希望隱藏的元素,如果javascript被關閉可見。我想我可以通過添加上面的隱藏類來做到這一點,但我會怎麼做呢?

謝謝!

回答

3

刪除".CO_accountForm"display:none屬性,而是在document.ready事件中通過javascript隱藏/設置display:none屬性。

即:

$(document).ready(function(){  
    // hide the form using JS so that if the browser 
    // doesn't support JS then the form is always displayed. 
    $(".CO_accountForm").hide(); 
    $("#CO_createAccount").click(function(){   
     if(this.checked){    
      $(".CO_accountForm").show();   
     } else {    
      $(".CO_accountForm").hide();   
     }  
    }); 
}); 
+0

再次感謝。非常感激。這些是我應該理解的基本功能,所以我需要加強我的jQuery。 – Jason 2011-06-06 16:40:22

0

有無元素通過default--而是通過jQuery的隱藏它們的添加類可見。

1

爲什麼不直接在相關表單上添加<noscript>標籤?這將確保顯示錶單,因爲無論如何您都無法啓動任何JavaScript。