我正在製作一個健身應用程序,在每個練習頁上我有一個顯示'信息','數據輸入'和'進度'的按鈕。這是工作正常,但是,當按鈕被點擊divs頂層,並在同一時間顯示。jquery隱藏多個div onclick
我想要的是主要顯示的信息,但是當用戶單擊其他按鈕時,其他按鈕div被隱藏。因此一次只顯示一個div。
HTML
<div id="buttons">
<a class="Smallbutton" id="showInfo">
<img src="img/info.png" />
</a>
<a class="Smallbutton" id="showDataInput">
<img src="img/add-item.png" />
</a>
<a class="Smallbutton" id="showHistory">
<img src="img/bar-chart.png" />
</a>
</div>
<div class="info" style="display: none;">
<p>Position yourself on the edge of the chair and grab hold of the seat just under your legs. Do the crunches by lifting
yourself from the seat and bring the knees to your chest.</p>
</div>
<div class="dataInput" style="display: none;">
<form onsubmit="save_data()">
Reps:
<input id="reps" type="number" name="quantity" min="1" max="12" step="1" required>Sets:
<input id="sets" type="number" name="quantity" min="1" max="4" step="1" required>
<input type="submit" value="Add Log" onclick="insert(this.form.reps.value,this.form.sets.value);show();">
</div>
<div class="history" style="display: none;">
<div id="log"></div>
<!--clears all data in localstorage-->
<input type="button" value="Clear" onclick="clearLocal();" />
</div>
SCRIPT
//JQUERY SHOW/HIDE HISTORY
$(document).ready(function() {
$('#showHistory').click(function() {
$('.history').slideToggle("fast");
});
});
//JQUERY SHOW/HIDE DATA INPUT
$(document).ready(function() {
$('#showDataInput').click(function() {
$('.dataInput').slideToggle("fast");
});
});
//JQUERY SHOW/HIDE INFO
$(document).ready(function() {
$('#showInfo').click(function() {
$('.info').slideToggle("fast");
});
});
,這裏是我的jsfiddle http://jsfiddle.net/GYru6/
預先感謝您
我發現的東西這個例子中,我是http://jsfiddle.net/XwN2L/然而,當後我將代碼實施到我的網站所有div都一次顯示。
這是完美的,感謝您的信息! – user2336624