600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > js遍历数组 对象 json

js遍历数组 对象 json

时间:2020-02-14 20:29:00

相关推荐

js遍历数组 对象 json

<html><head><title>json</title><script language="javascript" type="text/javascript">window.onload = function(){//遍历数组$("blsz").onclick = function(){$("tta").value = "";//定义数组var sz = ["吃饭","睡觉","打豆豆"]//for in遍历(也可以用普通for遍历)for(ind in sz){$("tta").value += sz[ind]+" "; }}// 遍历对象$("bldx").onclick = function(){//清空$("tta").value = "";/*定义对象*/var obj = {"name":"程咬金","age":"45"}; /*遍历数组*/for(ind in obj){$("tta").value += obj[ind]+" ";}}// 遍历数组对象$("blszdx").onclick = function(){$("tta").value = "";/*定义数组对象*/var szobj = [{"name":"tom","age":"24"},{"name":"marry","age":"19"}];/*遍历*/for(ind in szobj){$("tta").value += szobj[ind].name+"--->"+szobj[ind].age+"\r\n";}}}function $(uid){return document.getElementById(uid); }</script></head><body><input type="button" value="数组遍历" id="blsz"/>|<input type="button" value="对象遍历" id="bldx"/>|<input type="button" value="数组对象遍历" id="blszdx"/><br/><div id="divtext"></div><textarea id="tta" style="font-size=20px; width:200px; height=100px;"></textarea></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。