我在我的项目中使用数据表进行健壮搜索,还有更多 datatable的优点,但是当我需要搜索框的值时,数据表的搜索不起作用。实际上,我需要搜索以及删除数据的搜索框的值,但是当我应用获取搜索框的值的代码时,搜索在datable中不起作用。数据表搜索不起作用
以下是我的代码。
<html>
<title>Example 1 - apply dataTable()</title>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables_themeroller.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script>
</head>
<body>
<div class="container">
<table cellpadding="0" cellspacing="0" border="0" class="dataTable" id="example">
<thead>
<tr>
<th>id</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr>
<td>21</td>
<td>varun</td>
</tr>
<tr>
<td>22</td>
<td>nitin</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Script代码:
<script>
$('#example').dataTable({"sPaginationType": "full_numbers"});
var table = $('#example').DataTable();
//getting the value of search box
$('.dataTables_filter input').unbind().keyup(function(e) {
var value = $(this).val();
if (value.length>3) {
alert(value);
table.search(value).draw();
} else {
//optional, reset the search if the phrase
//is less then 3 characters long
table.search('').draw();
}
});
</script>
请帮帮我, 由于提前
为什么你有unbind.keyUp功能呢?我的意思是,为什么解除绑定? –
其实我没有太多关于jQuery的知识,我从下面的链接中找到了这段代码http://stackoverflow.com/questions/26590778/how-to-get-value-entered-in-search-box-in-datatables和非常感谢你的宝贵意见,它拯救了我的一天。 –