<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery的 .click()方法</title>
<style>
p{
color: red;
margin: 5px;
cursor: pointer;
}
p:hover{
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<h1>练习1</h1>
<div id="target">
Click here
</div>
<br />
<div id="other">
Trigger the handler
</div>
<br />
<div id="yf">
test data
</div>
<h1>练习2</h1>
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Yet one more Paragraph</p>
<script>
$("#target").click(function(){
alert("Handler for .click() called");
})
$("#other").click(function(){
$("#target").click();
})
var user = { yfname: 'CodePlayer', yfage: 18 };
$("#yf").click(user,function(yf){
alert("aha:"+yf.data.yfname+"; age:"+yf.data.yfage);//aha:CodePlayer; age:18
})
$("p").click(function(){
$(this).slideUp();
})
</script>
</body>
</html>