我正在使用Foundation 4作爲自定義單選按鈕。基於無線電值顯示/隱藏div(自定義收音機,Foundation 4)
我的單選按鈕看起來像這樣:
<label for="cat"><input name="cat" value="jersey" type="radio" id="jersey" style="display:none;"><span class="custom radio"></span></label>
<label for="cat"><input name="cat" value="shorts" type="radio" id="shorts" style="display:none;"><span class="custom radio"></span></label>
<label for="cat"><input name="cat" value="shirts" type="radio" id="shirts" style="display:none;"><span class="custom radio"></span></label>
我的jQuery看起來是這樣的:
$('input[type=radio]').click(function(){
$('.area').hide();
$('#' + $(this).val()).show();
});
顯示div的看起來像這樣的HTML:
<div class='area' id="jersey">jersey</div>
<div class='area' id="shorts">shorts</div>
<div class='area' id="shirts">shirts</div>
<div class='area' id="reversible">reversible</div>
<div class='area' id="outerwear">outerwear</div>
<div class='area' id="helmets">helmets</div>
<div class='area' id="other">other</div>
有人以前與普通的單選按鈕一起工作,但我沒有運用這些自定義無線電來工作 鈕釦。誰能幫我嗎?謝謝!
爲什麼所有的單選按鈕都設爲'display:none;'? – j08691 2013-03-14 21:01:16
這是因爲'div'沒有編程'val()'來計算。像收音機,輸入和表單等。你可以嘗試使用'html()'而不是'val()'。或者嘗試測試每個'id'的值,比如'$ .attr(「id」)' – 2013-03-14 21:01:33
輸入被自定義元素替換,所以你不再點擊輸入,這就是爲什麼它不起作用。 – adeneo 2013-03-14 21:02:37