javascript 怎么获取外部文件.js中的数组值.js文件内容
varareaServer=[{"id":"6122","name":"神骑世界","order":"1","server":[{"id":"34579","name":...
var areaServer=[{"id":"6122","name":"神骑世界","order":"1",
"server":[{"id":"34579","name":"所有区服","order":"0","value":"0"}],
"value":"1"},{"id":"6613","name":"狼烟","order":"1",
"server":[{"id":"37952","name":"烽火万里","order":"0","value":"1001"}],"value":"2"}] 展开
"server":[{"id":"34579","name":"所有区服","order":"0","value":"0"}],
"value":"1"},{"id":"6613","name":"狼烟","order":"1",
"server":[{"id":"37952","name":"烽火万里","order":"0","value":"1001"}],"value":"2"}] 展开
3个回答
展开全部
直接用就可以,不如a.js包含
var areaServer=[{"id":"6122","name":"神骑世界","order":"1",
"server":[{"id":"34579","name":"所有区服","order":"0","value":"0"}],
"value":"1"},{"id":"6613","name":"狼烟","order":"1",
"server":[{"id":"37952","name":"烽火万里","order":"0","value":"1001"}],"value":"2"}];
再b.htm页面,需要先引用js文件,相对路径绝对路径都可以,但是必须是网络路径,而不是本地路径
<script type="text/javascript" src="a.js"></script>
<script type="text/javascript">
alert(areaServer[0].id);
</script>
var areaServer=[{"id":"6122","name":"神骑世界","order":"1",
"server":[{"id":"34579","name":"所有区服","order":"0","value":"0"}],
"value":"1"},{"id":"6613","name":"狼烟","order":"1",
"server":[{"id":"37952","name":"烽火万里","order":"0","value":"1001"}],"value":"2"}];
再b.htm页面,需要先引用js文件,相对路径绝对路径都可以,但是必须是网络路径,而不是本地路径
<script type="text/javascript" src="a.js"></script>
<script type="text/javascript">
alert(areaServer[0].id);
</script>
展开全部
1楼的回答是正确的
你引入的方式有问题
<script type="text/javascript" src="D:/a.js"></script>是不可以的
应该用url的方式
例如,将js文件放到页面的js子目录下,然后
<script type="text/javascript" src="js/a.js"></script>
你引入的方式有问题
<script type="text/javascript" src="D:/a.js"></script>是不可以的
应该用url的方式
例如,将js文件放到页面的js子目录下,然后
<script type="text/javascript" src="js/a.js"></script>
追问
3Q
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script type=“text/javascript” src="xxx/xxx.js"></script>
src 是你要引入的js 路径和名字。
src 是你要引入的js 路径和名字。
更多追问追答
追问
我知道啊 那么引入进来了后怎么取出.js文件中的数组内容啊?xx.js文件内容只有var areaServer=[{"id":"6122","name":"神骑世界","order":"1","server":[{"id":"34579","name":"所有区服","order":"0","value":"0"}],"value":"1"},{"id":"6613","name":"狼烟","order":"1","server":[{"id":"37952","name":"烽火万里","order":"0","value":"1001"}],"value":"2"}]
追答
直接用就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |