使用方法這裏介紹 - http://www.techiegyan.com/2008/07/09/using-jquery-check-boxes-and-radio-buttons/jQuery的行動IE
我想顯示一個字段中選擇「其他」單選按鈕時,並隱藏同場除此以外。
該方法在非IE瀏覽器上正常工作,但在IE上運行(幾乎)相反... 它看起來像IE在取消選擇選項時觸發「更改」事件,而不是選擇它時。
下面是HTML:
<div><label class="option" for="selection-1"><input type="radio" id="selection-1" name="submitted[selection]" value="10" checked="checked" class="form-radio"> 10</label></div>
<div><label class="option" for="selection-2"><input type="radio" id="selection-2" name="submitted[selection]" value="20" class="form-radio"> 20</label></div>
<div><label class="option" for="selection-3"><input type="radio" id="selection-3" name="submitted[selection]" value="50" class="form-radio"> 50</label></div>
<div><label class="option" for="selection-4"><input type="radio" id="selection-4" name="submitted[selection]" value="100" class="form-radio"> 100</label></div>
<div><label class="option" for="selection-5"><input type="radio" id="selection-5" name="submitted[selection]" value="0" class="form-radio">other</label></div>
<div id="other-selection-wrapper">
<label for="other-selection">other:</label>
<input type="text" maxlength="10" name="submitted[other_selection]" id="other-selection" size="10" value="" class="form-text">
</div>
和腳本代碼:
<script type="text/javascript">
$(document).ready(function(){
$('#other-selection-wrapper').hide();
$("input[@name='submitted[selection]']").change(function(){
if ($("input[@name='submitted[selection]']:checked").val() == '0')
{ $('#other-selection-wrapper').show(); }
else
{ $('#other-selection-wrapper').hide(); }
});
});
</script>
由於@中的@(「input [@ name ='submitted [selection]']」),您的代碼即使在FF中也失敗,因此在FF和IE8中刪除@工作正常。我嘗試了jsfiddle與最新的jquery – 2011-04-17 20:25:26
感謝您的「刪除@」修復 – joe 2011-04-18 13:20:11
我試過,順便說一句,使用鍵盤是這樣的:(a)選項卡到單選按鈕選項。 (b)使用箭頭鍵在它們之間移動。使用click()時,一切正常。 – joe 2011-04-18 13:27:44