javascript - 搜索不适用于数据表 1.10 上的输入标签

标签 javascript html jquery datatables

我有关于使用数据表进行搜索的示例:jsfiddle.net/rmLLo7z2

如果我删除输入标签并放上它是正常的文本。搜索正常。

但它不能用输入标签搜索。

最佳答案

需要设置data-searchdata-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/

相关文章:

javascript - typescript 编译时错误

php - 是否使用表作为容器?

javascript - 如何使用javascript删除特定的表格行?

javascript - 将 JQuery 动画转换为 Javascript/CSS3

javascript - 根据选择显示表单域

javascript - 计算鼠标速度的脚本的概念

javascript - 无法让 javascript slider 设置动画

html - 为什么这个 <audio> 不能在 Safari 中播放?

javascript - 将 HTML 标签的属性添加到股票数据以进行 JS 操作

javascript - 编辑scrollTop以使用href值