**
JQuery知识点归纳
**
1.JQuery是什么
javascript的代码框架,可以简化代码,提高效率。
2.JQuery load()
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<title>Jquery load()</title>
<script type="text/javascript">
function load(){
$("#tips").load("JqueryLoad",function(responseText, statusTXT, xhr){
$("#tips").val(responseText);
});
}
</script>
</head>
<body>
<h3><a href="#" onclick="load()">使用JQuery执行load方法</a></h3>
<input type="text" id="tips">
</body>
</html>
package com.sigar.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/JqueryLoad")
public class JqueryLoad extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("Jquery加载 =======Jquery load()");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
3.JQuery get()
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<title>JQuery get()</title>
<script type="text/javascript">
function get(){
$.get("JqueryLoad", function(data, status){
$("#getsth").html(data);
});
}
</script>
</head>
<body>
<input type="button" onclick="get()" value="JQuery get()">
<div id="getsth"></div>
</body>
</html>
4.JQuery post()
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<title>JQuery post()</title>
<script type="text/javascript">
function post(){
$.post("JqueryLoad", {name:"张三",age:18}, function(data, status){
$("#getsth").html(data);
});
}
</script>
</head>
<body>
<input type="button" onclick="post()" value="JQuery post()">
<div id="getsth"></div>
</body>
</html>
5.JQuery注册验证
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<title>用户注册demo</title>
<script type="text/javascript">
function checkUsername(){
var username = $("#username").val();
$.post("RegisterCheckUserServlet",{username:username},function(data,status){
if(data == 1){
$("#UNameTips").html("<font color='red'>用户名已存在</font>");
}
});
}
</script>
</head>
<body>
<table border="1px">
<tr>
<td>用户名</td>
<td><input type="text" name="username" id="username" onblur="checkUsername()"><span id="UNameTips"></span></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="注册"></td>
</tr>
</table>
</body>
</html>