点击按钮没反应
先上代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | <%@ page language= "java" contentType= "text/html; charset=utf-8" pageEncoding= "utf-8" %> <% String basePath = request.getScheme() + ":" + "//" + request.getServerName() + ":" + request.getServerPort() + "/" + request.getServletContext().getContextPath(); %> <!DOCTYPE html> <html> <head> <base href= "<%=basePath%>" > <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>图书查询</title> <script type= "text/javascript" src= "<%=basePath%>/resources/js/jquery-1.4.2.js" > $( "#search" ).click(function(){ alert( "Hello" ); }); </script> <%-- <!-- 使用jquery实现Ajax --> <script type= "text/javascript" > $( "#search" ).click(function() { window.alert( "hello" ); //单击查询按钮的时候触发ajax事件 alert( "hello" ); $.ajax({ url: "<%=basePath%>/SelectServlet" , type: "post" , data:{ bookID:$( "input[name=bookID]" ).val(), bookName:$( "input[name=bookName]" ).val(), catgoryName:$( "input[name=catgoryName]" ).val() }, //dataType指明Servlet给Ajax返回数据的数据格式 dataType: "json" , //result中存储了Servlet给Ajax返回数据的数据格式$("#music1").text(result.song1); success:function(result) { var selectedBook = eval(result); var content = null ; for (var i in selectedBook) { var id = selectedBook[i].id; var name = selectedBook[i].name; var type = selectedBook[i].type; var price = selectedBook[i].price; var description = selectedBook[i].description; content = content + "<tr><td>" + id + "</td><td>" + name + "</td><td>" + type + "</td><td>" + price + "</td><td>" + description + "</td></tr>" ; } $( "#cont>tr" ).remove(); $( "#cont" ).html(content); } }); }); </script> --%> </head> <body> <center> <h1>图书查询</h1> <p> 图书ID:<input type= "text" name= "bookID" > 图书名:<input type= "text" name= "bookName" > 分类:<input type= "text" name= "catgoryName" > <input type= "button" value= "查询" id= "search" > </p> <hr> <table width= "800px" cellspacing= "0px" cellpadding= "0px" border= "1px" > <thead> <tr> <th>图书ID</th> <th>书名</th> <th>分类</th> <th>价格</th> <th>描述</th> </tr> </thead> <tbody id= "cont" > <c:forEach items= "${books }" var= "Book" > <tr> <td>${Book.id}</td> <td>${Book.name}</td> <td>${Book.type}</td> <td>${Book.price}</td> <td>${Book.description}</td> </tr> </c:forEach> </tbody> </table> </center> </body> </html> |
因为点击按钮一直没反应,所以我就把点击按钮的功能变成了简单的弹窗功能,结果点击按钮还是没反应。浏览器的控制台不报任何错误,点击按钮没有任何反应。
0
收起
正在回答
2回答
有时页面无反应时,应该先去Consloe中查看是否有错误信息,譬如下图样式,而Sources是查看代码中是否有编译错误。是的,jsp页面中的代码执行顺序是从上向下执行的,所以需要将js代码写在底部。祝学习愉快~
chrismorgen
2018-08-29 10:09:16
如下图所示,建议同学点击Console看看有没有报错,祝学习愉快~
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧