我有关于使用数据表进行搜索的示例:jsfiddle.net/rmLLo7z2
如果我删除输入标签并放上它是正常的文本。搜索正常。
但它不能用输入标签搜索。
最佳答案
需要设置data-search
和data-order
属性,
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</tfoot>
<tbody>
<tr>
<td data-search="Tiger Nixon" data-order="Tiger Nixon"><input value="Tiger Nixon"/></td>
<td data-search="System Architect" data-order="System Architect"><input value="System Architect"/> </td>
<td data-search="Edinburgh" data-order="Edinburgh"><input value="Edinburgh"/></td>
</tr>
<tr>
<td data-search="Garrett Winters" data-order="Garrett Winters"><input value="Garrett Winters"/></td>
<td data-search="Accountant" data-order="Accountant"><input value="Accountant"/> </td>
<td data-search="Tokyo" data-order="Tokyo"><input value="Tokyo"/></td>
</tr>
<tr>
<td data-search="Ashton Cox" data-order="Ashton Cox"><input value="Ashton Cox"/></td>
<td data-search="Junior Technical Author" data-order="Junior Technical Author"><input value="Junior Technical Author"/> </td>
<td data-search="San Francisco" data-order="San Francisco"><input value="San Francisco"/></td>
</tr>
<tr>
<td data-search="Cedric Kelly" data-order="Cedric Kelly"><input value="Cedric Kelly"/></td>
<td data-search="Senior Javascript Developer" data-order="Senior Javascript Developer"><input value="Senior Javascript Developer"/> </td>
<td data-search="Edinburgh" data-order="Edinburgh"><input value="Edinburgh"/></td>
</tr>
</tbody>
</table>
http://jsfiddle.net/rmLLo7z2/3/
关于数据属性
的更多信息:https://datatables.net/examples/advanced_init/html5-data-attributes.html
关于javascript - 搜索不适用于数据表 1.10 上的输入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793777/