2
沒有工作,所以我有一些HTML像這樣:jQuery的圖像選擇在IE7
<div id="avatar_choices">
<label for="id_choice_0">
<input id="id_choice_0" type="radio" name="choice" value="7" />
<img src="someimage.jpg" />
</label>
<label for="id_choice_1">
<input id="id_choice_1" type="radio" name="choice" value="8" />
<img src="someimage2.jpg" />
</label>
</div>
和一些腳本:
$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
$('#avatar_choices img').css('border', '2px solid #efefef');
$(this).css('border', '2px solid #39c');
$(this).siblings('input').attr('checked', 'checked');
});
我們的目標是讓用戶點擊周圍的圖像選項,讓選中的一個以邊框顏色突出顯示。
這在FF中正常工作。出於某種原因,在IE瀏覽器中點擊圖片後,點擊另一張圖片,然後嘗試點擊第一張圖片,邊框不會改變(雖然它會被選中)。
編輯: 我的解決方案最終發生了一半意外。我改變了代碼,這是由於redsquare的答案:
$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
$('#avatar_choices img').removeClass('selected');
$(this).addClass('selected');
$(this).siblings('input').attr('checked', 'checked');
});
其中:
#avatar_choices img.selected{border:2px solid #39c;}
進入數字。
所以改變的東西使用addClass和removeClass修復了這個問題。去搞清楚。 – defrex 2008-10-17 08:37:24