<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery中click事件传参</title>
<link rel="stylesheet" type="text/css" href="inputAndDiv.css">
</head>
<body style="background-color: #CCE8CF;">
<h3 style="color: #cd1636;">jquery中click事件传参</h3>
<input id="input1" type="button" value="jquery中事件对象">
<br/><br/>
<input id="input2" type="button" value="jquery中click事件传参">
<br/><br/>
<a id="a1" href="http://www.baidu.com">百度</a><br/>
在A标签的onclick中写return false;可以阻止超链接的默认URL跳转行为,但是写return 0;没效果<br/>
<a id="a2" href="http://www.qq.com" onclick="return false;">腾讯</a>
<a id="a2" href="http://www.163.com" onclick="return 0;">网易</a>
<br/><br/>
<a id="a3" href="https://blog.csdn.net/wd4java/article/details/49619573">
参考网页https://blog.csdn.net/wd4java/article/details/49619573
</a>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$('#input1').click(function(eve) {
console.log(this.value);
console.log(eve);
console.log(eve.target);
console.log(eve.type);
console.log(eve.which);
});
var userInfo = { fullName:'令狐冲', age:17, hobby: '任盈盈' };
//jquery中click事件传参
$('#input2').click(userInfo, function(eve) {
console.log(this);
console.log(eve);
console.log(eve.data);
//得到userInfo对象中的数据
console.log(eve.data.fullName, eve.data.age, eve.data.hobby);
});
var hometown = '江西省赣州市于都县';
//jquery中click事件传参
$('#input2').click(hometown, function(eve) {
//得到hometown变量数据
console.log(eve.data);
});
/*
如果通过click()函数绑定的事件处理函数的返回值为false,则可以阻止元素的默认事件行为,并停
止事件在DOM树中冒泡。例如超链接的click事件的处理函数返回false,可以阻止超链接的默认URL跳转行为。
*/
//点击超链接时,阻止链接跳转
$("#a1").click(function() {
return false;
});
</script>
</html>