<!DOCTYPE html><html lang="zh_hans"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><script src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script></head><body><ul><li>01</li><li>02</li><li>03</li><li>04</li></ul><form action=""><input type="email" name="" id="" /><input type="password" name="" id="" /><button type="submit">提交</button></form></body><script>// 3. 事件委派$("ul").delegate("li", "click", function () {alert("hello");});// 4. 事件切换$("ul li:first-child").hover(function () {$(this).prop("style", "color: red;");},function () {$(this).prop("style", "color: blue;");});// 5. 事件//当元素失去焦点时触发$("form input[type='email']").blur(function () {alert("hello");});//当元素被点击时触发$("form input[type='email']").click(function () {alert("world");});//当提交表单时触发$("form").submit(function () {alert("已提交");});</script></html>

<!DOCTYPE html><html lang="zh_hans"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><script src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script></head><body><form><input type="email" name="email" /><input type="password" name="password" /><button type="button">提交</button></form><div></div></body><script>// Ajax操作$("form button").click(function () {//序列表表格内容为字符串var data = $("form").serialize();console.log(data);$.ajax({url: "login.php",type: "POST",data: data,dataType: "json",success: function (res) {console.log(res);var str = res.email + res.password;$("div").html(str);},});});</script></html>
<?php$email = $_POST['email'];$password = $_POST['password'];$arr = array("email"=>$email, "password"=>$password);$json_obj = json_encode($arr);echo $json_obj;

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号