javascript对象与数组的例子
下面图老师小编要跟大家分享javascript对象与数组的例子,简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!
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;ilen;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;ilen;i++){
for(var j=0,len2=arr1[i].length;jlen2;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