<!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. 事件
//當(dāng)元素失去焦點(diǎn)時觸發(fā)
$("form input[type='email']").blur(function () {
alert("hello");
});
//當(dāng)元素被點(diǎn)擊時觸發(fā)
$("form input[type='email']").click(function () {
alert("world");
});
//當(dāng)提交表單時觸發(fā)
$("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 () {
//序列表表格內(nèi)容為字符串
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;
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號