請看看我的test page,我的問題是在「選擇圖片」組中查找所選單選按鈕的值。獲取組中選中的單選按鈕的值問題?
在裝載我用下面的代碼:
var currentImageFile = $("input:radio[name=selectedImage]:checked").val();
其左側的「選擇圖片」格拿起默認圖像。到現在爲止還挺好。
現在的問題是,當一個「選擇圖片」單選按鈕,隨後點擊我的事件代碼:
$("input:radio[name=selectedImage]").click(function() {
currentImageFile = $(this).val();
alert($(this).val());
});
(警報僅用於測試)返回完全沒有價值!
的HTML是非常直截了當:
<li><div class="xmasImage rounded" rel="http://www.completeinsight.co/resources/xmasHR/56269.jpg">
<img class="rounded" src="http://www.completeinsight.co/resources/xmasLR/56269_p.jpg" width="65" height="65" border="0" alt="56269" />
<div class="imageSelect"><input type="radio" name="selectedImage" value="56269">
<label for="selectedImage">56269</label>
</div>
</div></li>
我缺少明顯的?
如果使用change()事件而不是點擊操作,它會更好嗎? –
你糾正了這個問題嗎?在Chrome,FF和IE中運行良好。 – rooney
@SurrealDreams:它不應該,儘管change()可能會更可取。即使單選按鈕已被選中,點擊()將會觸發; change()不會。 – Blazemonger