我在这里做了两个处理,
. checkbox引入iCheck插件做样式
. button单击触发ajax请求
在未分离partial页面时是成功的,分离后可以请求到数据列,但checkbox样式和button的click失效。请各位指点!谢谢。
页面HTML,通过ajax请求在tbody处写入列表行,css和js文件已引入
<table class="table table-bordered table-striped table-actions">
<thead>
<tr>
<th width="50" class="text-center">选择</th>
<th width="100" class="text-center">交易日期</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody id="contentBox"></tbody>
</table>
页面js代码
$(document).ready(function() {
$.get(url, function(particalPage, status) {
$("#contentBox").html(particalPage);
});
$(".mb-control").on("click", function() {
alert($(this).data("action"));
});
});
partial页面HTML
<% rs.forEach(function(item){ %>
<tr>
<td class="text-center">
<label class="check "><input type="checkbox" class="icheckbox itemcheck" value=""/></label>
</td>
<td class="text-center"><%= item.exchangeTime %></td>
<td class="text-center">
<button type="button" class="btn btn-default btn-rounded btn-sm mb-control" data-box="#mb-cancel" data-action="/admin/customerorder/Cancel?id=<%= item.customerOrderID%>">
<span class="fa fa-times"></span>
作废
</button>
<%}%>
</td>
</tr>
<% }) %>
谢谢_yeshuai,我试了一下,写在外面还是运行不了,但是如下是可以的:
//这个可以
$("tbody").delegate("button", "click", function() {
alert("aaa");
});
//这个不行
$("button").delegate(".mb_control", "click", function() {
alert("aaa");
});
$("tbody").delegate("button", "click", function() {
alert("aaa");
});