國際巫師聯盟主席
葛來分多級長
巫審加碼首席巫師
這是沒有函式庫的程式設計師
From: xlzx.com
From: wangyi120.com
The HTML DOM Tree of Objects
http://www.w3schools.com/js/js_htmldom.asp
<html>
<head>
<title>網頁標題</title>
</head>
<body>
<p>段落一</p>
<p>段落二</p>
<p>段落三</p>
</body>
</html>
<html>
<head>
<title>網頁標題</title>
</head>
<body>
<p>段落一</p>
<p>段落二</p>
<p>段落三</p>
<button>Button 1</button>
</body>
</html>
The HTML DOM Tree of Objects
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
https://developers.google.com/speed/libraries/#libraries
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.min.js"></script>
<html>
<head>
<title>網頁標題</title>
</head>
<body>
<p>段落一</p>
<p>段落二</p>
<p>段落三</p>
<button>Button 1</button>
</body>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</html>
... 略
</body>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$('p').hide();
</script>
</html>
將所有DOM含有 p 的元素隱藏
... 略
</body>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(function() {
$('p').hide();
});
</script>
</html>
修改後的結果
Demo
Practice #0 Demo
Practice #0 Demo
Practice #0 Demo
<p id="myid">text1</p>
<p class="myclass">text2</p>
<ul>
<li>1</li>
<li class="active">2</li>
</ul>
<p id="myid">text1</p>
<p class="myclass">text2</p>
<ul>
<li>1</li>
<li class="active">2</li>
</ul>
$('#myid')
$('.myclass')
$('ul li.active')
$('ul .active')
The HTML DOM Tree of Objects
複習一下
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
$('button').click(function() {
$('ul .active').hide('slow');
});
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
$('button').click(function() {
$('ul .active').slideUp();
});
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
$('button').click(function() {
$('ul .active')
.slideUp('slow')
.slideDown();
});
Practice #1 Demo
Practice #1 Demo
Practice #1 Demo
Practice #2 Demo
Practice #2 Demo
Practice #2 Demo
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
</ul>
<button>Press me</button>
<ul>
<li>item 0</li>
<li class="active">item 1</li>
</ul>
$('button').click(function() {
$('.active') .text('jQuery!');
});
<button>Press me</button>
<input type="text" id="word">
<ul>
<li>item 0</li>
<li class="active">item 1</li>
</ul>
$('button').click(function() {
var word = $('#word') .val();
$('.active') .text(word);
});
step by step
直接來個Demo ㄎㄎ
大家都掌握了jQuery的精隨了
我也沒什麼好教的了
接下來 就來簡單介紹一些應用及實用的plugins
<( _ _ )>