<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="JQuery/jquery-2.0.0.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(function () {
var intArray = [10, 20, 30, 40, 50];
//用each方法来遍历普通数组
//如果想要跳出循环,只能用return false,而不能用break
var result= $.each(intArray, function (index,element) {//和map方法不同的是,回调函数的参数顺序不同
alert(index + " " + element);
});
var data = { name: "张三", sex: "男", age: 18 };
$.each(data, function (key,value) {
alert(key + " " + value);
});
});
</script>
</body>
</html>
JQuery中的each方法遍历数组和对象
最新推荐文章于 2022-01-07 08:59:26 发布