SlideShare a Scribd company logo
1 of 5
JavaScript & jQuery 基本入門
MARK CHEN

2014/1/19

1
JavaScript – Types of Data
內建三種基本資料型態(primitive data type)
數值(number)
NaN不等於任何值,NaN也不等於NaN

字串(string)
布林值(boolean)

複合資料型態(composite data type)
物件(object)
特殊的值
null → var x = null;
 null表示沒有任何東西

undefined

→ var x; 或 void x;

 當試圖去取得某個沒指定任何值、或null、或properties的變數時,就會出現undefined的結果

2014/1/19

2
Object
建立Object:
var obj = new Object();
或使用物件實字(Object literal)的方式
建立:
var obj = {};
也可為Object直接設定properties:
var person = {
name: „Mark‟,
age: 30
};

2014/1/19

只要簡單指定就可以幫Object直接
加上新的properties或是function
obj.x = 10;
obj.y = „This is string!‟;
存取properties的表示法
obj.x; > 10
obj[„x‟]; > 10

3
Function
function是物件,是Function的實例
也因為是Function的實例,所以可以將function傳給另
一個變數參考
var max = new Function('num1', 'num2', 'return num1 > num2 ? num1 : num2');
或
function max(num1, num2) {
return num1 > num2 ? num1 : num2;
}
var maximum = max;

2014/1/19

4
使用jQuery
<script src=“js/jquery-1.8.3-min.js”></script>
<script>
$(document).ready(function(){
//Code is write here
)};
</script>

$(document).ready()的作用就是等網頁全部都
載入完成之後,才開始執行Javascript
使用jQuery從$()開始
$(„#menu‟).hover(
function(){
$(„#submenu‟).show();

 簡潔寫法:
<script src=“js/jquery-1.8.3-min.js”></script>
<script>
$(function(){
//Code is write here
)};
</script>

2014/1/19

},
function(){
$(„#submenu‟).hide();
}
);

5

More Related Content

Viewers also liked

Batching and Incremental Build
Batching and Incremental BuildBatching and Incremental Build
Batching and Incremental BuildLearningTech
 
20120504 tsql temp_table
20120504 tsql temp_table20120504 tsql temp_table
20120504 tsql temp_tableLearningTech
 
Proof of conecpt ms build property command 20120504 joncash-02
Proof of conecpt ms build property command 20120504 joncash-02Proof of conecpt ms build property command 20120504 joncash-02
Proof of conecpt ms build property command 20120504 joncash-02LearningTech
 
Ltc Meeting 20120507
Ltc Meeting 20120507Ltc Meeting 20120507
Ltc Meeting 20120507LearningTech
 
Prototypes and inheritance in javascript
Prototypes and inheritance in javascriptPrototypes and inheritance in javascript
Prototypes and inheritance in javascriptLearningTech
 
20131004 - Css - Basic & Styling by 懿鋆
20131004 - Css - Basic & Styling by 懿鋆20131004 - Css - Basic & Styling by 懿鋆
20131004 - Css - Basic & Styling by 懿鋆LearningTech
 
Knockoutjs – custom bindings
Knockoutjs – custom bindingsKnockoutjs – custom bindings
Knockoutjs – custom bindingsLearningTech
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Hervé Vũ Roussel
 

Viewers also liked (9)

Batching and Incremental Build
Batching and Incremental BuildBatching and Incremental Build
Batching and Incremental Build
 
20120504 tsql temp_table
20120504 tsql temp_table20120504 tsql temp_table
20120504 tsql temp_table
 
Proof of conecpt ms build property command 20120504 joncash-02
Proof of conecpt ms build property command 20120504 joncash-02Proof of conecpt ms build property command 20120504 joncash-02
Proof of conecpt ms build property command 20120504 joncash-02
 
Config
ConfigConfig
Config
 
Ltc Meeting 20120507
Ltc Meeting 20120507Ltc Meeting 20120507
Ltc Meeting 20120507
 
Prototypes and inheritance in javascript
Prototypes and inheritance in javascriptPrototypes and inheritance in javascript
Prototypes and inheritance in javascript
 
20131004 - Css - Basic & Styling by 懿鋆
20131004 - Css - Basic & Styling by 懿鋆20131004 - Css - Basic & Styling by 懿鋆
20131004 - Css - Basic & Styling by 懿鋆
 
Knockoutjs – custom bindings
Knockoutjs – custom bindingsKnockoutjs – custom bindings
Knockoutjs – custom bindings
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS
 

More from LearningTech

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Mark java script & jquery 基本入門

  • 1. JavaScript & jQuery 基本入門 MARK CHEN 2014/1/19 1
  • 2. JavaScript – Types of Data 內建三種基本資料型態(primitive data type) 數值(number) NaN不等於任何值,NaN也不等於NaN 字串(string) 布林值(boolean) 複合資料型態(composite data type) 物件(object) 特殊的值 null → var x = null;  null表示沒有任何東西 undefined → var x; 或 void x;  當試圖去取得某個沒指定任何值、或null、或properties的變數時,就會出現undefined的結果 2014/1/19 2
  • 3. Object 建立Object: var obj = new Object(); 或使用物件實字(Object literal)的方式 建立: var obj = {}; 也可為Object直接設定properties: var person = { name: „Mark‟, age: 30 }; 2014/1/19 只要簡單指定就可以幫Object直接 加上新的properties或是function obj.x = 10; obj.y = „This is string!‟; 存取properties的表示法 obj.x; > 10 obj[„x‟]; > 10 3
  • 4. Function function是物件,是Function的實例 也因為是Function的實例,所以可以將function傳給另 一個變數參考 var max = new Function('num1', 'num2', 'return num1 > num2 ? num1 : num2'); 或 function max(num1, num2) { return num1 > num2 ? num1 : num2; } var maximum = max; 2014/1/19 4
  • 5. 使用jQuery <script src=“js/jquery-1.8.3-min.js”></script> <script> $(document).ready(function(){ //Code is write here )}; </script> $(document).ready()的作用就是等網頁全部都 載入完成之後,才開始執行Javascript 使用jQuery從$()開始 $(„#menu‟).hover( function(){ $(„#submenu‟).show();  簡潔寫法: <script src=“js/jquery-1.8.3-min.js”></script> <script> $(function(){ //Code is write here )}; </script> 2014/1/19 }, function(){ $(„#submenu‟).hide(); } ); 5