Skip to content

Commit 8ae1be3

Browse files
committed
去空格神器trim方法
1 parent df15867 commit 8ae1be3

File tree

3 files changed

+82
-49
lines changed

3 files changed

+82
-49
lines changed

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

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,26 @@
44
<head>
55
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
66
<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>
187
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
198
</head>
20-
9+
2110
<body>
22-
<h2>each方法</h2>
23-
<p>慕课网,专注分享</p>
24-
<div id="aaron"></div>
25-
点击观察结果:
26-
<select id="animation">
27-
<option value="1">each数组</option>
28-
<option value="2">each对象</option>
29-
</select>
30-
<input id="exec" type="button" value="执行动画">
11+
<h2>trim方法</h2>
12+
13+
未处理
14+
<input type="text" name="" id="results1" value=" 前后留空 " />
15+
<input id="exec1" type="button" value="点击执行"> <br />
16+
17+
trim处理
18+
<input type="text" name="" id="results2" value=" 前后留空 " />
19+
<input id="exec2" type="button" value="点击执行">
3120
<script type="text/javascript">
32-
$("#exec").click(function() {
33-
var v = $("#animation").val();
34-
var $aaron = $("#aaron");
35-
$aaron.empty();
36-
if (v == "1") {
21+
$("#exec1").click(function() {
22+
alert("值的长度:" + $("#results1").val().length)
23+
});
3724

38-
// 遍历数组元素
39-
$.each(['Aaron', '慕课网'], function(i, item) {
40-
$aaron.append("索引=" + i + "; 元素=" + item);
41-
});
42-
} else if (v == "2") {
43-
// 遍历对象属性
44-
$.each({
45-
name: "张三",
46-
age: 18
47-
}, function(property, value) {
48-
$aaron.append("属性名=" + property + "; 属性值=" + value);
49-
});
50-
}
25+
$("#exec2").click(function() {
26+
alert("值的长度:" + $.trim($("#results2").val()).length)
5127
});
5228
</script>
5329
</body>
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+
12+
div {
13+
width: 200px;
14+
height: 100px;
15+
background-color: yellow;
16+
color: red;
17+
}
18+
</style>
19+
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
20+
</head>
21+
22+
<body>
23+
<h2>each方法</h2>
24+
<p>慕课网,专注分享</p>
25+
<div id="aaron"></div>
26+
点击观察结果:
27+
<select id="animation">
28+
<option value="1">each数组</option>
29+
<option value="2">each对象</option>
30+
</select>
31+
<input id="exec" type="button" value="执行动画">
32+
<script type="text/javascript">
33+
$("#exec").click(function() {
34+
var v = $("#animation").val();
35+
var $aaron = $("#aaron");
36+
$aaron.empty();
37+
if (v == "1") {
38+
39+
// 遍历数组元素
40+
$.each(['Aaron', '慕课网'], function(i, item) {
41+
$aaron.append("索引=" + i + "; 元素=" + item);
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>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
p {
99
color: red;
1010
}
11-
div{
12-
width:200px;
13-
height: 100px;
11+
12+
div {
13+
width: 200px;
14+
height: 100px;
1415
background-color: yellow;
15-
color:red;
16+
color: red;
1617
}
1718
</style>
1819
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
@@ -32,20 +33,20 @@ <h2>inArray方法</h2>
3233
$("#exec").click(function() {
3334
var v = $("#animation").val();
3435
var $aaron = $("#aaron");
35-
$aaron.empty();
36+
$aaron.empty();
3637
if (v == "1") {
3738

38-
var index = $.inArray('Aaron',['test','Aaron', 'array','慕课网']);
39+
var index = $.inArray('Aaron', ['test', 'Aaron', 'array', '慕课网']);
3940

40-
$aaron.text('Aaron的索引是: '+ index)
41+
$aaron.text('Aaron的索引是: ' + index)
4142

4243
} else if (v == "2") {
4344

4445
//指定索引开始的位置
45-
var index = $.inArray('a',['a','b','c','d','a','c'],2);
46+
var index = $.inArray('a', ['a', 'b', 'c', 'd', 'a', 'c'], 2);
4647

47-
$aaron.text('a的索引是: '+ index)
48-
}
48+
$aaron.text('a的索引是: ' + index)
49+
}
4950
});
5051
</script>
5152
</body>

0 commit comments

Comments
 (0)