jQuery没有执行

时间:2017-04-22 12:52:44

标签: jquery html jsp

我在使用jQuery执行一个非常简单的代码时遇到问题,无法找出问题所在,我正在使用这个JSP代码。

没有错误,也没有出现结果,也无法找到问题。

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
        $(document).ready(function(){
            // code to read selected table row cell data (values).
            $("#myTable").on('click','.btnSelect',function(){
                 alert("Hello");
            });
        });
        //*
</script>
<meta http-equiv="Content-Type" content="text/html">
<link type="text/css" rel="stylesheet" href="inc/style.css" />
<title>liste tickets</title>
</head>

这是表格,其中包含id&#34; myTable&#34;在循环结束时,您可以看到使用class =&#34生成的按钮; btnSelect&#34;

<table id="myTable">
            <tr>
                <th>Sujet</th>
                <th>Description</th>
                <th>Priorite</th>
                <th>ID Ticket</th>
                <th>Etat</th>
                <th>Date Soumise</th>
                <th>Action</th>                   
            </tr>
            <c:forEach items="${lticket }" var="ticket" varStatus="boucle">
            <tr id=j>
                <td id=i><c:out value="${ ticket.sujet }"/></td>
                <td><c:out value="${ ticket.description }"/></td>
                 <c:choose>
                    <c:when test="${ticket.priorite == 1 }">
                        <td><c:out value="Faible"/></td>
                    </c:when>
                    <c:when test="${ticket.priorite == 2 }">
                        <td><c:out value="Moyenne"/></td>
                    </c:when>
                    <c:when test="${ticket.priorite == 3 }">
                        <td><c:out value="Haute"/></td>
                    </c:when>
                    <c:otherwise>
                        <td><c:out value="Priorite non-défini"/></td>
                    </c:otherwise>
                 </c:choose>

                 <td><c:out value="${ ticket.id_ticket }"/></td>
                 <c:choose>
                    <c:when test="${ticket.etat == 1 }">
                        <td><c:out value="En attente de prise en charge"/></td>
                    </c:when>
                    <c:when test="${ticket.etat == 2 }">
                        <td><c:out value="En attente de votre validation"/></td>
                    </c:when>
                    <c:when test="${ticket.etat == 3 }">
                        <td><c:out value="Cloturé"/></td>
                    </c:when>
                    <c:otherwise>
                        <td><c:out value="Etat du ticket non-défini"/></td>
                    </c:otherwise>
                 </c:choose>
                 <td><c:out value="${ ticket.date_envoi }"/></td>
                 <td><button class="btnSelect">Selectionner</button></td>
            </tr>
            </c:forEach>
        </table>     

无论你点击什么,点击一个导航窗口都会显示文字:&#34;你好&#34;。

1 个答案:

答案 0 :(得分:4)

您不能将代码放在具有src的脚本代码中,它将被忽略。你需要单独的标签。

尝试:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<script>
        $(document).ready(function(){
            // code to read selected table row cell data (values).
            $("#myTable").on('click','.btnSelect',function(){
                 alert("Hello");
            });
        });        
</script>