Skip to content

Commit df15867

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

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

慕课网教程案例/jQuery入门教程/jQuery核心/查找数组中的索引inArray.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,26 @@ <h2>inArray方法</h2>
2525
点击观察结果:
2626
<select id="animation">
2727
<option value="1">inArray</option>
28-
<option value="2">each对象</option>
28+
<option value="2">inArray</option>
2929
</select>
3030
<input id="exec" type="button" value="执行动画">
3131
<script type="text/javascript">
3232
$("#exec").click(function() {
3333
var v = $("#animation").val();
3434
var $aaron = $("#aaron");
35-
$aaron.empty();
35+
$aaron.empty();
3636
if (v == "1") {
3737

38-
// 遍历数组元素
39-
var exist = $.inArray('Aaron',['Aaron', '慕课网']);
40-
41-
alert(exist)
38+
var index = $.inArray('Aaron',['test','Aaron', 'array','慕课网']);
39+
40+
$aaron.text('Aaron的索引是: '+ index)
4241

4342
} else if (v == "2") {
44-
// 遍历对象属性
45-
$.each({
46-
name: "张三",
47-
age: 18
48-
}, function(property, value) {
49-
$aaron.append("属性名=" + property + "; 属性值=" + value);
50-
});
43+
44+
//指定索引开始的位置
45+
var index = $.inArray('a',['a','b','c','d','a','c'],2);
46+
47+
$aaron.text('a的索引是: '+ index)
5148
}
5249
});
5350
</script>

0 commit comments

Comments
 (0)