【问题标题】:Table sorter on ajax outputajax输出上的表格排序器
【发布时间】:2018-01-16 07:24:05
【问题描述】:

我正在尝试显示一个 ajax 输出 (PHP) 的表格。即使我已将所有必要的属性添加到表中,也不会触发 tablesorter。我可以知道我哪里出错了。任何建议将不胜感激。

通过 ajax 输出 HTML

<table border=1 width="850" id="search" class="tablesorter"> 
    <thead>
        <tr>
            <!--<th><input type="checkbox" id="selectall"/></th>-->
            <th>SNo.</th> <th>UserName</th> <th>Product Name</th><th>Price </th><th>Quantity</th><th>Total price</th><th>Quarter</th>
        </tr>
    </thead>
    <tbody>
        <tr width=700> <td>1</td> <td>user</td>  <td>androidGUI</td> <td>101</td> <td>10</td> <td>1010</td> <td>Q4-13</td></tr>
        <tr width=700> <td>2</td> <td>user </td>  <td>androidGUI</td> <td>101</td> <td>10</td> <td>1010</td> <td>Q4-13</td></tr>
        <tr width=700> <td>3</td> <td>user</td>  <td>cat6k22</td> <td>789</td> <td>5</td> <td>3945</td> <td>Q4-13</td></tr>
        <tr width=700> <td>4</td> <td>user</td>  <td>HP21</td> <td>252</td> <td>25</td> <td>6300</td> <td>Q4-13</td></tr>
        <tr width=700> <td>5</td> <td>user</td>  <td>nexus</td> <td>101</td> <td>15</td> <td>1515</td> <td>Q4-13</td></tr>
    </tbody>
</table>

我的 Javascript:

<script type="text/javascript">
    $(function(){

$("select").multiselect({
    selectedList: 4,
            header: false


});

}); 
$( document ).ready(function() {
   $(function () {
    var frm = $('#searchreq');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
            //alert(data);
            document.getElementById("resultshower").innerHTML= data;
        }
    });
    ev.preventDefault();
});
});
});
$("#resultshower").ready(function() /*Also tried with $(document).ready still no use*/
    { 
       $("#search").tablesorter(); 
     } 
 ); 


</script>

同样的脚本可以在没有 ajax 调用的情况下工作。请把我看作 jQuery 的新手

【问题讨论】:

    标签: jquery ajax html-table


    【解决方案1】:

    你的括号和大括号弄乱了。试试这个:

    $("#resultshower").ready(function() /*Also tried with $(document).ready still no use*/
    { 
       $("#search").tablesorter(); 
    }); //You went wrong here
    

    而且你在 ajax 之前调用了两次 .ready() 函数。在这里检查:

    $(document).ready(function() {
    $(function () { //remove this line 
    .....
    .....
    }); // remove this line
    });
    

    【讨论】:

    • 看来复制粘贴错误。更新了我的代码..我的工作代码仍然正确放置了括号..仍然不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 2012-09-05
    • 2018-12-18
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多