Javascript tablesorter插件不起作用

时间:2018-08-07 17:03:04

标签: javascript html tablesorter

我正在尝试在代码中包含tablesorter插件,但是它不起作用。我已经添加了jquery库和tablesorter文件,但是它什么也没做。这是我的代码:

已添加脚本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="{% static 'MIDIPIRCUSSION_APP/jquery.tablesorter.js' %}"></script>

HTML代码:

    <div class="jumbotron2">
            <div class="container">
            <br>
        <center>
        <table id="myTable" class="table table-dark"  style="text-align: center">
            <thead>
                <tr>
                    <th>Fecha de Creación</th>
                    <th>Título</th>
                    <th>Duracion</th>
                    <th>Dificultad</th>

                    {% if not user.is_staff %}

                        <th>Jugar</th>

                    {% endif %}

                    <th>Configurar Bateria</th>


                    {% if user.is_staff %}
                        <th>Modificar</th>
                        <th>Eliminar</th>
                    {% endif %}

            </thead>

            {% for cancion in object_list %}
            <tbody>
                <tr>
                    <td>{{cancion.creacion}}</td>
                    <td>{{cancion.titulo}}</td>
                    <td>{{cancion.duracion}}</td>
                    <td>{{cancion.dificultad}}</td>
</tbody>
</table>

javascript代码:

<script>
$(document).ready(function() { 
  $("myTable").tablesorter(); 
    });
</script>

2 个答案:

答案 0 :(得分:1)

选择器无效...应该为$("#myTable")

$("myTable")正在寻找不存在的标签<myTable></myTable>

答案 1 :(得分:0)

我发现了错误。我使用两种不同的方式来加载具有不同版本的jquery,因此我没有使用正确的方式。

相关问题