$(document).ready(function () {
// the filter div has the id of your table plus "_filter.
var $searchBox = $("#example_filter input[type='search']");
// remove current handlers
$searchBox.off();
// 按下enter执行搜索
$searchBox.on("keyup" ,function(evtObj){
if(evtObj.keyCode == 13){
$("#example").DataTable().search($searchBox.val()).draw();
}
});
// 搜索框后面加按钮搜索
$btn = $("<button type='button'>Go</button>");
$("#example_filter").append($btn);
$btn.click(function(evtObj){
$("#example").DataTable().search($searchBox.val()).draw();
})
});
//如果需要更复杂的
$(document).ready(function () {
//在每次初始化的时候执行一次
$("#example").one("preInit.dt", function () {
// the filter div has the id of your table plus "_filter.
var $searchBox = $("#example_filter input[type='search']");
// remove current handlers
$searchBox.off();
// 按下enter执行搜索
$searchBox.on("keyup" ,function(evtObj){
if(evtObj.keyCode == 13){
$("#example").DataTable().search($searchBox.val()).draw();
}
});
// 搜索框后面加按钮搜索
$btn = $("<button type='button'>Go</button>");
$("#example_filter").append($btn);
$btn.click(function(evtObj){
$("#example").DataTable().search($searchBox.val()).draw();
})
});
});
为了减少dataTable每次输入都会去查一次、浪费系统资源$(document).ready(function () { // the filter div has the id of your table plus "_filter. var $searchBox = $("#example_filter input[typ...