| 導購 | 订阅 | 在线投稿
分享
 
 
 

javascript對象與數組的例子

2008-08-29 06:39:47  編輯來源:互聯網  简体版  手機版  移動版  評論  字體: ||

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE> New Document </TITLE>

<META NAME="Generator" CONTENT="EditPlus">

<META NAME="Author" CONTENT="">

<META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT="">

<script type="text/javascript">

var arr = [{name:"張三",age:"1",sex:"男"},{name:"黑妞",hight:"1.5米"}];

var arr1 = [["張三","1","男"],["黑妞","1.5米"]];

function showArr(){

document.getElementById("out").innerHTML ="<br>";

for(var i=0,len = arr.length;i<len;i++){

var ob = arr[i];

for(var o in ob){

var str = ob[o];

document.getElementById("out").innerHTML += str+"<br>";

}

}

}

function showArr1(){

document.getElementById("out").innerHTML ="<br>";

for(var i=0,len=arr1.length;i<len;i++){

for(var j=0,len2=arr1[i].length;j<len2;j++){

document.getElementById("out").innerHTML += arr1[i][j]+"-----";

}

document.getElementById("out").innerHTML +="<br>";

}

}

</script>

</HEAD>

<BODY>

<table>

<tr>

<td >test</td>

<td bgColor="red">test</td>

<td bgColor="red"><input type="button" value="按鈕" onclick="showArr();"/></td>

<td bgColor="red"><input type="button" value="按鈕2" onclick="showArr1();"/></td>

</tr>

</table>

<div id="out"></div>

</BODY>

</HTML>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script type="text/javascript"> var arr = [{name:"張三",age:"1",sex:"男"},{name:"黑妞",hight:"1.5米"}]; var arr1 = [["張三","1","男"],["黑妞","1.5米"]]; function showArr(){ document.getElementById("out").innerHTML ="<br>"; for(var i=0,len = arr.length;i<len;i++){ var ob = arr[i]; for(var o in ob){ var str = ob[o]; document.getElementById("out").innerHTML += str+"<br>"; } } } function showArr1(){ document.getElementById("out").innerHTML ="<br>"; for(var i=0,len=arr1.length;i<len;i++){ for(var j=0,len2=arr1[i].length;j<len2;j++){ document.getElementById("out").innerHTML += arr1[i][j]+"-----"; } document.getElementById("out").innerHTML +="<br>"; } } </script> </HEAD> <BODY> <table> <tr> <td >test</td> <td bgColor="red">test</td> <td bgColor="red"><input type="button" value="按鈕" onclick="showArr();"/></td> <td bgColor="red"><input type="button" value="按鈕2" onclick="showArr1();"/></td> </tr> </table> <div id="out"></div> </BODY> </HTML>
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
王朝網路微信公眾號
微信掃碼關註本站公眾號 wangchaonetcn
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有