jquery在頁面第二次載入的時候觸發不了下拉框的change事件,啟動tomcat,網址列輸入localhost:8080/aa/list.jsp時能夠觸發下拉框的change事件,但是從servlet 過來後就不行了,怎麼回事?
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>信息界面</title> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#sel_emp").live('change',function(){ var value = $('#sel_emp').val(); alert(value); window.location = "/aa/servlet/Test1Servlet"; }); }); </script> </head> <body> <select id="sel_emp"> <option value="1">编号</option> <option value="2">姓名</option> </select> <table border="1"> <tr> <th>编号</th> <th>姓名</th> </tr> <c:forEach items="${list }" var="element"> <tr> <td>${element.uid }</td> <td>${element.username }</td> </tr> </c:forEach> </table> </body> </html>
------------------------servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Employee employee_01 = new Employee(); employee_01.setUid("1"); employee_01.setUsername("张三"); Employee employee_02 = new Employee(); employee_02.setUid("2"); employee_02.setUsername("李四"); List<Employee> list = new ArrayList<Employee>(); list.add(employee_01); list.add(employee_02); request.setAttribute("list", list); request.getRequestDispatcher("/list.jsp").forward(request, response);
問題補充:
你是指,從servlet 跳到該頁面後,點選下拉選單,選擇一個值的時候,不會觸發這下面這個:
引用
# function(){ # # $("#sel_emp").live('change',function(){ # var value = $('#sel_emp').val(); # alert(value); # window.location = "/aa/servlet/Test1Servlet"; # }
是麼?
是的
#問題補充:
你是指,從servlet 跳到該頁面後,點選下拉選單,選擇一個值的時候,不會觸發這下面這個:
引用
# function(){ # # $("#sel_emp").live('change',function(){ # var value = $('#sel_emp').val(); # alert(value); # window.location = "/aa/servlet/Test1Servlet"; # }
是麼?
是的
#以上是jquery觸發select的change事件失效的問題解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!