[英]Last Clicked Radio button ID
我有由多行組成的表,每一行由第一欄中的單選按鈕組成,如下所示:
<table class="table table-condensed span8" id="AllocationTable">
<thead>
<tr>
<th title="Entity to Allocate" style="width: 30%">Entity</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.EntityAllocations)
{
<tr>
<td>
<input type="radio" name="radio" id="@item.ID" class="EntityRadioSelect" value="@item.ID" onclick="EntitySelect(this)" disabled="disabled" >
</td>
</tr>
}
</tbody>
</table>
現在,我想捕獲最后單擊的單選按鈕的ID,我已經嘗試過類似的操作
function EntitySelect(select) {
if ($(select).parent().data("lastClicked")){
alert($(select).parent().data("lastClicked"));
}
$(select).parent().data("lastClicked", select.id);
}
但是我得到了錯誤的值,因為它給了我當前值,有時還給了我無法接受的其他值。
var clicked='';
var preClicked='';
$("#AllocationTable").on("click",".EntityRadioSelect",function(){
preClicked=clicked;
clicked=$(this).attr("id");
});
刪除onclick =“ EntitySelect(this)”
嘗試這個:
function EntitySelect(select) {
var parent=$(select).parents('#AllocationTable');
if (parent.data("lastClicked")){
alert(parent.data("lastClicked"));
}
parent.data("lastClicked", select.id);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.