Home > Web Front-end > JS Tutorial > body text

Solution to the problem that jquery triggers the change event of select to fail

黄舟
Release: 2017-06-27 09:48:20
Original
5999 people have browsed it

jquery cannot trigger the change event of the drop-down box when the page is loaded for the second time. Start tomcat and enter localhost:8080/aa/list.jsp in the address bar. It can trigger the change event of the drop-down box, but from servlet It doesn’t work after I came here. What’s going on?

<%@ 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(&#39;change&#39;,function(){
			var value = $(&#39;#sel_emp&#39;).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>
Copy after login

---------------------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);		
Copy after login

Question supplement:

You mean, after jumping to the page from the servlet, clicking the drop-down menu and selecting a value will not trigger the following:

Quote

# function(){  
#           
#         $("#sel_emp").live(&#39;change&#39;,function(){  
#             var value = $(&#39;#sel_emp&#39;).val();  
#             alert(value);  
#             window.location = "/aa/servlet/Test1Servlet";  
#         }
Copy after login
Copy after login

Is it?

Yes

## Question supplement:

Do you mean , after jumping to the page from the servlet, clicking the drop-down menu and selecting a value, the following will not be triggered:

citation

# function(){  
#           
#         $("#sel_emp").live(&#39;change&#39;,function(){  
#             var value = $(&#39;#sel_emp&#39;).val();  
#             alert(value);  
#             window.location = "/aa/servlet/Test1Servlet";  
#         }
Copy after login
Copy after login

, right?

Yes

The above is the detailed content of Solution to the problem that jquery triggers the change event of select to fail. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template