我讀了很多關於計算器的事情,但沒有幫助我:(如何檢測這個單選按鈕是否被選中?
我有這樣的HTML表格,通過Ajax請求加載:
<table class="table table-striped table-hover choix_annonce_table">
<thead>
<tr>
<th>Sélection</th>
<th>Visuel</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="radio" value="45" name="idAnnonce"></td>
<td><img alt="Annonce 1" src=""></td>
</tr>
<tr>
<td><input type="radio" value="46" name="idAnnonce"></td>
<td><img alt="Annonce 2" src=""></td>
</tr>
</tbody>
</table>
我嘗試當單選按鈕被選中來檢測,但沒有以下問題的工作(在js文件包括在我的 「主」 頁):
$(document).ready(function() {
$("input[name=idAnnonce]").click(function(){
alert("xx");
});
});
OR
$(document).ready(function() {
$("input[name=idAnnonce]:radio").change(function() {
alert("xx");
});
});
你有想法嗎?
編輯:當我加載JS直接到我的加載表與Ajax,它的工作原理。 爲什麼?
的可能的複製【使用方法上的改變事件無線電?(http://stackoverflow.com/questions/13152927/how-to-use-radio -on-change-event) – robbmj
閱讀選中的屬性? 'console.log(this.checked);' – epascarello
[Find out if if radio button is checked with JQuery?](http://stackoverflow.com/questions/2272507/find-out-if-radio-button-使用jquery進行檢查) – Heroselohim