- 多個fieldset,怎麼通過button按鈕同時只顯示一個呢
-
<a class="mini-button" id="button3" style="" onclick="">用戶名</a>
<a class="mini-button" id="button4" style="" onclick="">最喜愛</a>
<fieldset>
<legend>用戶名與密碼:</legend>
<input name="hiddenField" type="hidden" value="hiddenvalue" />
<label for="username">用戶名:</label>
<input type="text" id="username" value="www.dreamdu.com" />
<label for="pass">密碼:</label>
<input type="password" id="pass" />
</fieldset>
<fieldset>
<legend>性別:</legend>
<label for="boy">男</label>
<input type="radio" value="1" id="sex" />
<label for="girl">女</label>
<input type="radio" value="2" id="sex" />
<label for="sex">保密</label>
<input type="radio" value="3" id="sex" />
</fieldset>
<fieldset>
<legend>我最喜愛的:</legend>
<label for="computer">計算機</label>
<input type="checkbox" value="1" id="fav" />
<label for="trval">旅游</label>
<input type="checkbox" value="2" id="fav" />
<label for="buy">購物</label>
<input type="checkbox" value="3" id="fav" />
</fieldset>
比如說這段代碼,我想通過兩個按鈕來控制,點擊第一個按鈕時顯示上面的,點擊第二個按鈕顯示下面的,請問如何實現?
最佳回答:
<a class="mini-button" id="button3" style="" onclick="toogleFD('un')">用戶名</a>
<a class="mini-button" id="button4" style="" onclick="toogleFD('favor')">最喜愛</a>
<script>
function toogleFD(id) {
id = document.getElementById(id);
id.style.display = id.style.display == 'none' ? 'block' : 'none'
}
</script>
<fieldset id="un">
<legend>用戶名與密碼:</legend>
<input name="hiddenField" type="hidden" value="hiddenvalue" />
<label for="username">用戶名:</label>
<input type="text" id="username" value="www.dreamdu.com" />
<label for="pass">密碼:</label>
<input type="password" id="pass" />
</fieldset>
<fieldset>
<legend>性別:</legend>
<label for="boy">男</label>
<input type="radio" value="1" id="sex" />
<label for="girl">女</label>
<input type="radio" value="2" id="sex" />
<label for="sex">保密</label>
<input type="radio" value="3" id="sex" />
</fieldset>
<fieldset id="favor">
<legend>我最喜愛的:</legend>
<label for="computer">計算機</label>
<input type="checkbox" value="1" id="fav" />
<label for="trval">旅游</label>
<input type="checkbox" value="2" id="fav" />
<label for="buy">購物</label>
<input type="checkbox" value="3" id="fav" />
</fieldset>