您可以使用“数据事件”来处理您的事件:
html:
<table id="table">
<thead>
<tr>
<th data-field="name">Name</th>
<th data-field="isStudent"
data-formatter="formatStudent"
data-events="studentEvents">Is Student</th>
<th data-field="isTeacher"
data-formatter="teacherStudent"
data-events="teacherEvents">Is Teacher</th>
</tr>
</thead>
</table>
js:
var data = [
{id: 0, name: 'joe1', isStudent: 0, isTeacher: 0},
{id: 1, name: 'joe2', isStudent: 1, isTeacher: 0},
{id: 2, name: 'joe3', isStudent: 0, isTeacher: 1},
{id: 3, name: 'joe4', isStudent: 1, isTeacher: 1},
{id: 4, name: 'joe5', isStudent: 0, isTeacher: 0}
];
$(function () {
$('#table').bootstrapTable({
data: data
});
});
function formatStudent(value, row, index) {
return '<input type="checkbox" id="d_' + row["id"] +'"' + ((value != 0) ? ' checked ' : '') + '>';
}
window.studentEvents = {
'click :checkbox': function (e, value, row, index) {
// do something
}
};
function teacherStudent(value, row, index) {
return '<input type="checkbox" id="d_' + row["id"] +'"' + ((value != 0) ? ' checked ' : '') + '>';
}
window.teacherEvents = {
'click :checkbox': function (e, value, row, index) {
// do something
}
};
文档在这里:http ://bootstrap-table.wenzhixin.net.cn/documentation/#column-options