SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
玩玩JQUERY
13年8月23⽇日星期五
Who am I ...
•Ethan - 陳禕寰
•MiCloud 前端⼯工程師(F2E)
13年8月23⽇日星期五
HTML
13年8月23⽇日星期五
JavaScript
13年8月23⽇日星期五
JQUERY
$(‘Knowledge’).appendTo(‘You’)
13年8月23⽇日星期五
What is jQuery?
It’s basically JavaScript
made more accessible.
13年8月23⽇日星期五
With JavaScript, cross-
browser Ajax looks like...
13年8月23⽇日星期五
With jQuery, it’s as
simple as this...
// Get the html data.
$.get('ajax/test.html',function(data){
$('#results').append(data);
});
13年8月23⽇日星期五
With JavaScript, you would
style elements like this...
var elems = document.getElementsByClassName(‘ethan’),
len = elems.length,
i = 0;
for( i = 0; i < len; i++ ){
elems[i].style.backgroundColor = ‘green’;
}; before
after
13年8月23⽇日星期五
With jQuery, it’s just a
simple one-liner...
$(‘.ethan’).css(‘backgroundColor’,‘green’);
before
after
13年8月23⽇日星期五
Let’s you write less
and do more
13年8月23⽇日星期五
“What does that mean?”
jQuery allows you to easily
select elements on a page
and manipulate or add some
new behaviour to them.
13年8月23⽇日星期五
What the jQuery can do?
• Simplifies traversing the DOM
• Powerful selection engine
• Eases element styling through JavaScript
• Powerful methods for element animation
• Cross-browser Ajax interactions
• DOM data-storage
• and more!
13年8月23⽇日星期五
Normalises many cross-browser quirks
so don’t have to worry about them
13年8月23⽇日星期五
Hi! I’m IE6
13年8月23⽇日星期五
jQuery
• It’s open-source
• Great for beginners wishing to ‘break’ into
front-end web development
• Developers from any other language
background can start using it easily
13年8月23⽇日星期五
Let’s start jQuery
13年8月23⽇日星期五
Go to jQuery.com
13年8月23⽇日星期五
How to use it?
• Create a new HTML file
• Include jQuery using <script> tag
• Load it from the Google CDN.This can be faster than
self-hosting
<script src=‘javascript/jquery-1.10.1.min.js’></script>
<script src=‘http://code.jquery.com/jquery-1.10.1.min.js’></script>
13年8月23⽇日星期五
Using jQuery
In most cases, your code should run when the
document has finished loading
<script type=‘text/javascript’>
$(document).ready(function(){
// your code should go here
});
// alternatively
$(function(){
// your code should go here
});
</script>
13年8月23⽇日星期五
What is $?
• $ is an alias to jQuery
• Code can either use $ or just jQuery
$(document).ready(function(){
// your code should go here
});
// same as...
jQuery(document).ready(function(){
// your code should go here
});
13年8月23⽇日星期五
jQuery Structure
• Ajax
• Attributes
• Callbacks
object
• Core
• CSS
• Data
• Deferred
Object
• Deprecated
• Dimensions
• Effects
• Events
• Forms
• Internals
• Manipulation
• Miscellaneous
• Offset
• Properties
• Removed
• Selectors
• Traversing
• Utilities
13年8月23⽇日星期五
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Basic Selectors
// ID selector
$(‘#jquery’)
// Class selector
$(‘.ethan’)
// Element selector
$(‘div’)
// wildcard selector
$(‘*’)
// Attribute selector
$(‘input[name=ethanName]’)
13年8月23⽇日星期五
What if I want to select
an element that’s a child
of another element?...
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Filter Selectors
//first element in a result set
$(‘ul li:first’)
//last element in a result set
$(‘ul li:last’)
//all odd elements in a result set
$(‘ul li:odd’)
//all even elements
$(‘ul li:even’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Filter Selectors
//first element in a result set
$(‘ul li:first’)
//last element in a result set
$(‘ul li:last’)
//all odd elements in a result set
$(‘ul li:odd’)
//all even elements
$(‘ul li:even’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Filter Selectors
//first element in a result set
$(‘ul li:first’)
//last element in a result set
$(‘ul li:last’)
//all odd elements in a result set
$(‘ul li:odd’)
//all even elements
$(‘ul li:even’)
13年8月23⽇日星期五
<div class=‘welcome’></div>
<ul id=‘jquery’>
<li class=‘ethan’>micloud</li>
<li class=‘ethan’>Ethan</li>
<li class=‘ethan’>Team</li>
<li class=‘ethan’>mitac</li>
<li class=‘ethan’>HI</li>
</ul>
<input type=‘text’
name=‘ethanName’ value=’hi’ />
Filter Selectors
//first element in a result set
$(‘ul li:first’)
//last element in a result set
$(‘ul li:last’)
//all odd elements in a result set
$(‘ul li:odd’)
//all even elements
$(‘ul li:even’)
13年8月23⽇日星期五
Selectors
• Element selector
• ID and Class selectors
• Attribute selectors
• Pseudo selectors
• $(‘p’)
• $(‘div #things’)
• $(‘input[type=text]’)
• $(‘input:focus’)
An extremely powerful way to specify which elements you want.
13年8月23⽇日星期五
Effects
• Show and Hide
• Fade
• Animate
• more...!
• $(‘#ethan’).show()
• $(‘#ethan’).fadeOut()
• $(‘#ethan’).animate(...)
Making things look pretty.
13年8月23⽇日星期五
Event
• Events in general
• A problem
• bind() and live()
• Introducing on()
$(‘button’).click(function(){alert(‘Clicked!’)})
$(‘.cat’).click(function(){alert(‘Clicked!’)})
$(...).bind(...) $(...).live(...)
$(‘button’).on(‘click’, function(){alert(‘Clicked!’)})
Responding to user actions
13年8月23⽇日星期五
Just do it!
http://jsbin.com/evajoZU/5/edit
Please Clone
13年8月23⽇日星期五
Front-End Debug tool
13年8月23⽇日星期五
Yeoman
13年8月23⽇日星期五
Lots of Generators
13年8月23⽇日星期五
13年8月23⽇日星期五
Just do it!
npm install -g yo
npm install -g generator-webapp
yo webapp
13年8月23⽇日星期五
參考資料
• JS Bin http://jsbin.com
• Yeoman http://yeoman.io/
• jetstrap https://jetstrap.com
• Open Data Platform http://odf.micloud.tw/
• Bootstrap http://getbootstrap.com/
• jQuery UI http://jqueryui.com/
13年8月23⽇日星期五
13年8月23⽇日星期五

Mais conteúdo relacionado

Mais procurados

Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...irwinvifxcfesre
 
Working With Ajax Frameworks
Working With Ajax FrameworksWorking With Ajax Frameworks
Working With Ajax FrameworksJonathan Snook
 
Occam razor kiss testing stage
Occam razor kiss testing stageOccam razor kiss testing stage
Occam razor kiss testing stageIevgenii Katsan
 
Occam Razor & KISS-Driven Test Automation
Occam Razor &  KISS-Driven Test AutomationOccam Razor &  KISS-Driven Test Automation
Occam Razor & KISS-Driven Test AutomationDeutsche Post
 
Back To The Front - Javascript Test Driven Development is between us (workshop)
Back To The Front - Javascript Test Driven Development is between us (workshop)Back To The Front - Javascript Test Driven Development is between us (workshop)
Back To The Front - Javascript Test Driven Development is between us (workshop)Marco Cedaro
 
JavascriptMVC
JavascriptMVCJavascriptMVC
JavascriptMVC4lb0
 
Intro to jQuery UI
Intro to jQuery UIIntro to jQuery UI
Intro to jQuery UIappendTo
 

Mais procurados (10)

JQuery primer
JQuery primerJQuery primer
JQuery primer
 
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
 
Working With Ajax Frameworks
Working With Ajax FrameworksWorking With Ajax Frameworks
Working With Ajax Frameworks
 
Occam razor kiss testing stage
Occam razor kiss testing stageOccam razor kiss testing stage
Occam razor kiss testing stage
 
Occam Razor & KISS-Driven Test Automation
Occam Razor &  KISS-Driven Test AutomationOccam Razor &  KISS-Driven Test Automation
Occam Razor & KISS-Driven Test Automation
 
Back To The Front - Javascript Test Driven Development is between us (workshop)
Back To The Front - Javascript Test Driven Development is between us (workshop)Back To The Front - Javascript Test Driven Development is between us (workshop)
Back To The Front - Javascript Test Driven Development is between us (workshop)
 
JavascriptMVC
JavascriptMVCJavascriptMVC
JavascriptMVC
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Jquery ui, ajax
Jquery ui, ajaxJquery ui, ajax
Jquery ui, ajax
 
Intro to jQuery UI
Intro to jQuery UIIntro to jQuery UI
Intro to jQuery UI
 

Destaque

JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsSimon Su
 
Brocade - Stingray Application Firewall
Brocade - Stingray Application FirewallBrocade - Stingray Application Firewall
Brocade - Stingray Application FirewallSimon Su
 
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析Simon Su
 
JCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop SetupJCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop SetupSimon Su
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試Simon Su
 
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionGCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionSimon Su
 

Destaque (6)

JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
 
Brocade - Stingray Application Firewall
Brocade - Stingray Application FirewallBrocade - Stingray Application Firewall
Brocade - Stingray Application Firewall
 
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
 
JCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop SetupJCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop Setup
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
 
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionGCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow Introduction
 

Mais de Simon Su

Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic OperationSimon Su
 
Google IoT Core 初體驗
Google IoT Core 初體驗Google IoT Core 初體驗
Google IoT Core 初體驗Simon Su
 
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoTJSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoTSimon Su
 
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務Simon Su
 
Google Cloud Platform Special Training
Google Cloud Platform Special TrainingGoogle Cloud Platform Special Training
Google Cloud Platform Special TrainingSimon Su
 
GCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage GuideGCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage GuideSimon Su
 
GCPNext17' Extend 開始GCP了嗎?
GCPNext17' Extend   開始GCP了嗎?GCPNext17' Extend   開始GCP了嗎?
GCPNext17' Extend 開始GCP了嗎?Simon Su
 
Try Cloud Spanner
Try Cloud SpannerTry Cloud Spanner
Try Cloud SpannerSimon Su
 
Google Cloud Monitoring
Google Cloud MonitoringGoogle Cloud Monitoring
Google Cloud MonitoringSimon Su
 
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKEGoogle Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKESimon Su
 
Docker in Action
Docker in ActionDocker in Action
Docker in ActionSimon Su
 
Google I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News UpdateGoogle I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News UpdateSimon Su
 
IThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOpsIThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOpsSimon Su
 
Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3Simon Su
 
Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧Simon Su
 
GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)Simon Su
 
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile SolutionsGoogle Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile SolutionsSimon Su
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(下)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)Simon Su
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)Simon Su
 
GCPUG.TW - 2016活動討論
GCPUG.TW - 2016活動討論GCPUG.TW - 2016活動討論
GCPUG.TW - 2016活動討論Simon Su
 

Mais de Simon Su (20)

Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic Operation
 
Google IoT Core 初體驗
Google IoT Core 初體驗Google IoT Core 初體驗
Google IoT Core 初體驗
 
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoTJSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
 
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
 
Google Cloud Platform Special Training
Google Cloud Platform Special TrainingGoogle Cloud Platform Special Training
Google Cloud Platform Special Training
 
GCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage GuideGCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage Guide
 
GCPNext17' Extend 開始GCP了嗎?
GCPNext17' Extend   開始GCP了嗎?GCPNext17' Extend   開始GCP了嗎?
GCPNext17' Extend 開始GCP了嗎?
 
Try Cloud Spanner
Try Cloud SpannerTry Cloud Spanner
Try Cloud Spanner
 
Google Cloud Monitoring
Google Cloud MonitoringGoogle Cloud Monitoring
Google Cloud Monitoring
 
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKEGoogle Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKE
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Google I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News UpdateGoogle I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News Update
 
IThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOpsIThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOps
 
Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3
 
Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧
 
GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)
 
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile SolutionsGoogle Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(下)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
 
GCPUG.TW - 2016活動討論
GCPUG.TW - 2016活動討論GCPUG.TW - 2016活動討論
GCPUG.TW - 2016活動討論
 

玩玩jquery

  • 2. Who am I ... •Ethan - 陳禕寰 •MiCloud 前端⼯工程師(F2E) 13年8月23⽇日星期五
  • 6. What is jQuery? It’s basically JavaScript made more accessible. 13年8月23⽇日星期五
  • 7. With JavaScript, cross- browser Ajax looks like... 13年8月23⽇日星期五
  • 8. With jQuery, it’s as simple as this... // Get the html data. $.get('ajax/test.html',function(data){ $('#results').append(data); }); 13年8月23⽇日星期五
  • 9. With JavaScript, you would style elements like this... var elems = document.getElementsByClassName(‘ethan’), len = elems.length, i = 0; for( i = 0; i < len; i++ ){ elems[i].style.backgroundColor = ‘green’; }; before after 13年8月23⽇日星期五
  • 10. With jQuery, it’s just a simple one-liner... $(‘.ethan’).css(‘backgroundColor’,‘green’); before after 13年8月23⽇日星期五
  • 11. Let’s you write less and do more 13年8月23⽇日星期五
  • 12. “What does that mean?” jQuery allows you to easily select elements on a page and manipulate or add some new behaviour to them. 13年8月23⽇日星期五
  • 13. What the jQuery can do? • Simplifies traversing the DOM • Powerful selection engine • Eases element styling through JavaScript • Powerful methods for element animation • Cross-browser Ajax interactions • DOM data-storage • and more! 13年8月23⽇日星期五
  • 14. Normalises many cross-browser quirks so don’t have to worry about them 13年8月23⽇日星期五
  • 16. jQuery • It’s open-source • Great for beginners wishing to ‘break’ into front-end web development • Developers from any other language background can start using it easily 13年8月23⽇日星期五
  • 19. How to use it? • Create a new HTML file • Include jQuery using <script> tag • Load it from the Google CDN.This can be faster than self-hosting <script src=‘javascript/jquery-1.10.1.min.js’></script> <script src=‘http://code.jquery.com/jquery-1.10.1.min.js’></script> 13年8月23⽇日星期五
  • 20. Using jQuery In most cases, your code should run when the document has finished loading <script type=‘text/javascript’> $(document).ready(function(){ // your code should go here }); // alternatively $(function(){ // your code should go here }); </script> 13年8月23⽇日星期五
  • 21. What is $? • $ is an alias to jQuery • Code can either use $ or just jQuery $(document).ready(function(){ // your code should go here }); // same as... jQuery(document).ready(function(){ // your code should go here }); 13年8月23⽇日星期五
  • 22. jQuery Structure • Ajax • Attributes • Callbacks object • Core • CSS • Data • Deferred Object • Deprecated • Dimensions • Effects • Events • Forms • Internals • Manipulation • Miscellaneous • Offset • Properties • Removed • Selectors • Traversing • Utilities 13年8月23⽇日星期五
  • 23. Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> 13年8月23⽇日星期五
  • 24. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) 13年8月23⽇日星期五
  • 25. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) 13年8月23⽇日星期五
  • 26. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) 13年8月23⽇日星期五
  • 27. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) 13年8月23⽇日星期五
  • 28. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Basic Selectors // ID selector $(‘#jquery’) // Class selector $(‘.ethan’) // Element selector $(‘div’) // wildcard selector $(‘*’) // Attribute selector $(‘input[name=ethanName]’) 13年8月23⽇日星期五
  • 29. What if I want to select an element that’s a child of another element?... 13年8月23⽇日星期五
  • 30. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Filter Selectors //first element in a result set $(‘ul li:first’) //last element in a result set $(‘ul li:last’) //all odd elements in a result set $(‘ul li:odd’) //all even elements $(‘ul li:even’) 13年8月23⽇日星期五
  • 31. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Filter Selectors //first element in a result set $(‘ul li:first’) //last element in a result set $(‘ul li:last’) //all odd elements in a result set $(‘ul li:odd’) //all even elements $(‘ul li:even’) 13年8月23⽇日星期五
  • 32. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Filter Selectors //first element in a result set $(‘ul li:first’) //last element in a result set $(‘ul li:last’) //all odd elements in a result set $(‘ul li:odd’) //all even elements $(‘ul li:even’) 13年8月23⽇日星期五
  • 33. <div class=‘welcome’></div> <ul id=‘jquery’> <li class=‘ethan’>micloud</li> <li class=‘ethan’>Ethan</li> <li class=‘ethan’>Team</li> <li class=‘ethan’>mitac</li> <li class=‘ethan’>HI</li> </ul> <input type=‘text’ name=‘ethanName’ value=’hi’ /> Filter Selectors //first element in a result set $(‘ul li:first’) //last element in a result set $(‘ul li:last’) //all odd elements in a result set $(‘ul li:odd’) //all even elements $(‘ul li:even’) 13年8月23⽇日星期五
  • 34. Selectors • Element selector • ID and Class selectors • Attribute selectors • Pseudo selectors • $(‘p’) • $(‘div #things’) • $(‘input[type=text]’) • $(‘input:focus’) An extremely powerful way to specify which elements you want. 13年8月23⽇日星期五
  • 35. Effects • Show and Hide • Fade • Animate • more...! • $(‘#ethan’).show() • $(‘#ethan’).fadeOut() • $(‘#ethan’).animate(...) Making things look pretty. 13年8月23⽇日星期五
  • 36. Event • Events in general • A problem • bind() and live() • Introducing on() $(‘button’).click(function(){alert(‘Clicked!’)}) $(‘.cat’).click(function(){alert(‘Clicked!’)}) $(...).bind(...) $(...).live(...) $(‘button’).on(‘click’, function(){alert(‘Clicked!’)}) Responding to user actions 13年8月23⽇日星期五
  • 37. Just do it! http://jsbin.com/evajoZU/5/edit Please Clone 13年8月23⽇日星期五
  • 42. Just do it! npm install -g yo npm install -g generator-webapp yo webapp 13年8月23⽇日星期五
  • 43. 參考資料 • JS Bin http://jsbin.com • Yeoman http://yeoman.io/ • jetstrap https://jetstrap.com • Open Data Platform http://odf.micloud.tw/ • Bootstrap http://getbootstrap.com/ • jQuery UI http://jqueryui.com/ 13年8月23⽇日星期五