語法:
- $.each(object,callback)
- 例如:陣列
Var stations=[“台北”,”板橋” ,”桃園” ,”新竹” ,”台中” ,”嘉義” ,”台南” ,”高雄”];
- 方式一:$.each(stations,function(){…});
- 方式二:$(stations).each(function(){…})
範例:
03 |
< script type = "Text/JavaScript" src = "js/jQuery.js" ></ script > |
04 |
< script type = "Text/JavaScript" > |
05 |
$(document).ready(function(){ |
06 |
var stations=['台北','板橋' ,'桃園' ,'新竹' ,'台中' ,'嘉義' ,'台南' ,'高雄']; |
08 |
$('#btn1').click(function(){ |
09 |
$.each(stations,function(){ |
10 |
$('#div1').append('< p >' + this + '</ p >'); |
13 |
$('#btn2').click(function(){ |
14 |
$(stations).each(function(){ |
15 |
$('#div1').append('< p >' + this + '</ p >'); |
23 |
background-color:yellow; |
30 |
< FORM action = "" method = POST id = form1 name = form1 > |
31 |
< input type = "button" id = "btn1" value = "設定每個P的內容" /> |
32 |
< input type = "button" id = "btn2" value = "設定每個P的內容" /> |
34 |
< div id = "div1" >我是div1</ div > |
|