$(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
属性,并通过JavaScript隐藏/设置display:none
属性document.ready
事件。
即:
$(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 - 如果 javascript 关闭,则可以显示/隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6255139/