<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
function OpenConsole(name) {
//第一步 声明一个数组
//第二步 往里面进行添加
// var jsonObj = {HostNav:[{name:"测试热点",ath:"ath",atv:"atv",text:"内容",CJName:""}]}
var jsonObj = {HostNav:[]}
console.log(1);
console.log(jsonObj);
console.log(1);
var addHost={name:"测试热点",ath:"ath1",atv:"atv1",text:"内容1",CJName:"1"}
jsonObj.HostNav.push(addHost);
console.log(jsonObj);
//第三步 添加
for (var i = 0; i < jsonObj.HostNav.length ; i++) {
if(jsonObj.HostNav[i].name == "测试热点"){
console.log(jsonObj.HostNav[i].name);
}else{alert(jsonObj.HostNav[i].name);}
};}
</script>
<style type="text/css">
#btnConsolo{
width: 100px;
height: 100px;
border:1px solid red;
}
</style>
</head>
<body>
<div id="btnConsolo" οnclick="OpenConsole();" ></div>
</body>
</html>
js的数组追加
最新推荐文章于 2024-04-25 00:00:00 发布