Skip to Content
深入淺出 jQuery
book

深入淺出 jQuery

by Ryan Benedetti, Ronan Cranley
February 2012
Intermediate to advanced
540 pages
11h 39m
Chinese
GoTop Information, Inc.
Content preview from 深入淺出 jQuery
110 第三章
讓事情在你的頁面上發生
var = function (){
var numRand = (4);
$( ).each(function(index, value) {
if(numRand == index){
$(this).append("<span id=' '></ >");
return false;
}
}
my_scripts.js
jQuery 磁貼解答
看看你是否能夠安排下列磁貼,新建一個名為 hideCode 的具名函式。該函式使
用條件邏輯,將新的 span 元素( ID has_discount)隨機地隱藏在既有的可點
擊的 .guess_box div 元素中。
清單裡的元素的索引指出它在清單上的位
置。
索引總是從 0 開始。
因此, 一個 素具 有索 0 2
個具有索引 1,依此類推。我們在第 6 章檢視陣列和迴圈時,
還會看到更多有關索引的使用。
span
".guess_box"
has_discount
getRandom
hideCode
});
條件邏輯,將我
們在清單中所處
的位置與隨機數
字作比較。
我們的具名函式
呼叫隨機數字產生函式。
中斷 .each() 迴圈。
將 has_discount 元素附
加到 .guess_box 類別的
某個元素。
目前位置 4 111
jQuery 事件函式
太棒了﹗折扣訊息每次都
會將它自己隱藏在不同的方框裡。這些
函式真的越來越好用了。
function checkForCode(){ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5 錦囊妙計

HTML5 錦囊妙計

Christopher Schmitt, Kyle Simpson
Pro JSF and HTML5: Building Rich Internet Components, Second Edition

Pro JSF and HTML5: Building Rich Internet Components, Second Edition

Hazem Saleh, Allan Lykke Christensen, Zubin Wadia

Publisher Resources

ISBN: 9789862764060