自动关注jQuery DataTable的搜索框
问题描述:
我找不到在页面加载时自动关注jQuery Datatable的Search Box的方法.
I am unable to find a way to auto focus on jQuery Datatable's Search Box on page load.
这里的问题是此文本框未提供ID,因此我无法访问它.
The problem here is that this Text box is not given a ID and so i'm unable to access it.
有人可以帮我解决这个问题.
Can someone help me with this issue.
Datatable的示例位于 https://datatables.net/examples/advanced_init/html5-data-options.html
An example of Datatable is at https://datatables.net/examples/advanced_init/html5-data-options.html
谢谢!
答
您可以使用jquery进行此操作:
You can do this with jquery:
$(function() {
$('#datatabelID [type="search"]').focus()
});
或
$('div.dataTables_filter input').focus()
只需将数据表ID与上述选择器一起使用,您就可以访问搜索文本框.
Just use your datatable Id with the above selector, and you are bale to access the search textbox.