$('#activityTable tbody').on('click', "input[type='radio']", function () {
var activityId = $(this).val();
var activityName = $(this).attr('activityName');
$("#activityId").val(activityId);
$("#create-activitySrc").val(activityName);
$("#findMarketActivity").modal("hide");
});
<!-- 查找市场活动 -->
<div class="modal fade" id="findMarketActivity" role="dialog">
<div class="modal-dialog" role="document" style="width: 80%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">查找市场活动</h4>
</div>
<div class="modal-body">
<div class="btn-group" style="position: relative; top: 18%; left: 8px;">
<form class="form-inline" role="form">
<div class="form-group has-feedback">
<input id="searchActivityNameTxt" type="text" class="form-control" style="width: 300px;"
placeholder="请输入市场活动名称,支持模糊查询">
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
</form>
</div>
<table id="activityTable" class="table table-hover" style="width: 900px; position: relative;top: 10px;">
<thead>
<tr style="color: #B3B3B3;">
<td></td>
<td>名称</td>
<td>开始日期</td>
<td>结束日期</td>
<td>所有者</td>
<td></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
通过$('#activityTable tbody')拿不到,但是$('#activityTable')就可以,求解
已解决!!!
因为在动态填充数据如下
success: function (res) {
var htmlStr = "";
$(res).each(function () {
htmlStr += "<tr><td><input type=\"radio\" name=\"activity\" activityName='" + this.name + "' value='" + this.id + "'/></td>";
htmlStr += "<td>" + this.name + "</td>";
htmlStr += "<td>" + this.startDate + "</td>";
htmlStr += "<td>" + this.endDate + "</td>";
htmlStr += "<td>" + this.owner + "</td></tr>";
});
$('#activityTable').html(htmlStr);
!!! 应该使用 $('#activityTable tbody').html(htmlStr);
}
不然使用tableid用html会重新创建tbody导致不一致。