我的jQuery代码有问题,我使用“显示”和“隐藏”按钮来显示/隐藏类,但是jQuery仅适用于我的第一个类。我的代码是:
$(document).ready(function(){
$("#hide").click(function(){
$(".menu_sub_index").hide(500);
});
$("#show").click(function(){
$(".menu_sub_index").show(500);
});
});
<div class="danhmuc">
<button id="hide">⛔</button>
<button id="show">Category</button>
</div>
有任何改进我的代码的建议吗?谢谢!
答案 0 :(得分:0)
假设您的html元素如下所示。
<div class="menu_sub_index">Div Content</div>
<div class="danhmuc">
<button id="hide">⛔</button>
<button id="show">Category</button>
</div>
点击功能
$(document).ready(function(){
$("#hide").click(function(){
$(".menu_sub_index").hide();
});
$("#show").click(function(){
$(".menu_sub_index").show();
});
});
答案 1 :(得分:0)
尝试
$(document).ready(function(){
$("#hide").on("click", function(e){
$(".menu_sub_index").hide();
});
$("#show").on("click", function(e){
$(".menu_sub_index").show();
});
});
<div class="danhmuc">
<button id="hide">⛔</button>
<button id="show">Category</button>
</div>