一、表单序列化
serialize() 将表单中所有选中项拼凑成一个字符串。类似get请求参数
例如:username=jack&password=1234&gender=man&....
serializeArray()将表单中所有选中项拼凑一个json数组
<script type="text/javascript">
$(document).ready(function(){
alert($("form").serialize());
alert($("form").serializeArray());
});
</script>
二、事件冒泡
event.stopPropagation()
<!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">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// 事件冒泡:子元素事件执行时,一并触发父元素相同的事件
$("#outerDiv").click(function(){
alert("outerDiv");
});
$("#innerDiv").click(function(event){
alert("innerDiv");
//方式1:
//return false;
//方式2:通过event 提供函数
event.stopPropagation();
});
});
</script>
</head>
<body>
<div id="outerDiv" style="border:1px solid #f00;width:200px;height:200px">
<div id="innerDiv" style="border:1px solid #00f;width:100px;height:100px"></div>
</div>
<br/>
<span id="showSpan"></span>
</body>
</html>
三、浏览器默认动作
event.preventDefault() ;
<!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">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// href a标签默认行为,阻止
$("a").click(function(event){
alert("谈谈谈");
//方式1:
// return false;
//方式2:
event.preventDefault() ;
});
});
</script>
</head>
<body>
<a href="http://www.itheima.com">你点我呀</a>
</body>
</html>