<div class="container">
<div id="p1">
<button type="button">
b1
</button>
</div>
</div>
<div id="p2">
<button type="button" >
b2
</button>
</div>
</div>
<div id="p3">
<button type="button" >
b3
</button>
</div>
</div>
</div>
<!-- -->
<div >
<div id="G1" >
</div>
</div>
<div id="g2" >
</div>
</div>
<div id="g3" >
</div>
</div>
</div>
</div>
<div >
<div id="G9">
</div>
<div id="G7" >
</div>
<div id="G4" >
</div>
<div >
<div id="G5" >
</div>
<div id="G6" >
</div>
<div id="G3" >
</div>
</div>
我可以使用inarray,然后使用转换为数组的json数组,并在那些创建的数组上使用嵌套循环来显示和隐藏.json转换后的数据。我解决了问题,谢谢。允许你在你的身体之前得到你的JavaScript代码你的文件,在头部。
答案 0 :(得分:0)
我相信这就是你想要的:
$(document).ready(function() {
$(".fa-check").hide();
$(".z").click(function() {
$(".fa-check").hide();
$(this).find(".fa-check").show();
});
});
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div id="p1" class="z">
<i class="fa fa-check" ></i>
<div >
<button type="button" class="z1">
</button>
</div>
</div>
<div id="p2" class="z">
<i class="fa fa-check" ></i>
<div >
<button type="button" class="z2">
Married, No Kids
</button>
</div>
</div>
<div id="p3" class="z">
<i class="fa fa-check"></i>
<div >
<button type="button" id="z3">
Happy Family
</button>
</div>
</div>
</div>
</div>