Skip to content

Commit 8a118f8

Browse files
committed
查找数组中的索引inArray
1 parent 0f68a98 commit 8a118f8

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

慕课网教程案例/jQuery入门教程/jQuery核心/each方法的应用.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</style>
1818
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
1919
</head>
20-
20+
2121
<body>
2222
<h2>each方法</h2>
2323
<p>慕课网,专注分享</p>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
6+
<title></title>
7+
<style>
8+
p {
9+
color: red;
10+
}
11+
div{
12+
width:200px;
13+
height: 100px;
14+
background-color: yellow;
15+
color:red;
16+
}
17+
</style>
18+
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
19+
</head>
20+
21+
<body>
22+
<h2>inArray方法</h2>
23+
<p>慕课网,专注分享</p>
24+
<div id="aaron"></div>
25+
点击观察结果:
26+
<select id="animation">
27+
<option value="1">inArray</option>
28+
<option value="2">each对象</option>
29+
</select>
30+
<input id="exec" type="button" value="执行动画">
31+
<script type="text/javascript">
32+
$("#exec").click(function() {
33+
var v = $("#animation").val();
34+
var $aaron = $("#aaron");
35+
$aaron.empty();
36+
if (v == "1") {
37+
38+
// 遍历数组元素
39+
var exist = $.inArray('Aaron',['Aaron', '慕课网']);
40+
41+
alert(exist)
42+
43+
} else if (v == "2") {
44+
// 遍历对象属性
45+
$.each({
46+
name: "张三",
47+
age: 18
48+
}, function(property, value) {
49+
$aaron.append("属性名=" + property + "; 属性值=" + value);
50+
});
51+
}
52+
});
53+
</script>
54+
</body>
55+
56+
</html>

0 commit comments

Comments
 (0)