如果javascript关闭,可以显示/隐藏

$(document).ready(function(){ $("#CO_createAccount").click( function (){ if(this.checked){ $(".CO_accountForm").show(); } else { $(".CO_accountForm").hide(); } }); }); 

我将“.CO_accountForm”的css设置为“display:none;”

但是,如果关闭javascript,我希望隐藏元素可见。 我假设我可以通过添加上面的隐藏类来做到这一点,但我该怎么做呢?

谢谢!

删除".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(); } }); }); 

为什么不在相关表单周围添加

默认情况下元素是可见的 – 但是通过隐藏它们的jquery添加一个类。