怎么用js或者jquery 读取js或者css文件的全部内容?

JavaScript023

怎么用js或者jquery 读取js或者css文件的全部内容?,第1张

以ajax方式读取文件到字符串;

想要把css或者js内容做成json比较不靠谱,因为css中的选择器有带.的类选择器,有带#的id选择器,是不能作为标识符的,js内容也不容易分析。

直接用就可以,不如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>