-
Notifications
You must be signed in to change notification settings - Fork 1
/
js_jquery_0629.html
71 lines (64 loc) · 1.88 KB
/
js_jquery_0629.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.red {
color: red;
}
</style>
</head>
<body>
<!-- <div id="menu1" onclick="fun1();"> -->
<div>
主要選單 1
</div>
<ul>
<li>次選單 1-1</li>
<li>次選單 1-2</li>
<li>次選單 1-3</li>
</ul>
<!-- <div id="menu1" onclick="fun2();"> -->
<div>
主要選單 2
</div>
<ul>
<li>次選單 2-1</li>
<li>次選單 2-2</li>
<li>次選單 2-3</li>
</ul>
<div>
主要選單 3
</div>
<ul>
<li>次選單 3-1</li>
<li>次選單 3-2</li>
<li>次選單 3-3</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- 2. 開始寫jquery -->
<script>
// jq
$(document).ready(function () {
// div click
$('div').click(function () {
// console.log('this',this);
// const myThis = $(this).next().children();
// console.log('myThis',myThis);
// const nexlObj = myThis.next();
// $(this).next().hide();
// $(this).next().toggle();
// $(this).next().children().first().toggleClass('red');
$(this).next().toggleClass('red');
// next() 同層 最接近 ul
// children() 小孩層 最接近 li
});
// div click end
});
// jq end
</script>