-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents1.html
More file actions
34 lines (29 loc) · 909 Bytes
/
events1.html
File metadata and controls
34 lines (29 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery Events</title>
<link media="all" rel="stylesheet" href="day.css" type="text/css" />
</head>
<body>
<h1>My Website</h1>
<button data-file = "day">Day</button>
<button data-file = "night">Night</button>
<script src="jquery.js" type="text/javascript"></script>
<script>
(function(){
var link = $('link'); //定义变量link,将选择结果赋予变量
$('button').click(function(){
var $this = $(this), //这个$this要带$应该是用来标记this是个变量
stylesheet = $this.data('file'); //将data-file的值赋给stylesheet
link.attr('href', stylesheet+'.css'); //改变link的css链接值
$this
.siblings('button')
.removeAttr('disabled')
.end() //回到$this元素
.attr('disabled', 'disabled'); //将其属性设为不可用
});
})();
</script>
</body>
</html>