首先我的目录结构是如下: webroot下 有scripts文件夹下有test.js webroot->web-inf->views->index.jsp WebRoot
scripts
test.js
web-inf
views
index.jsp我的test.js 写了如下函数。返回值是一个对象
var c=function(){
return {
a:'bbb'
};
};我在index.jsp 下面如下导入的
<script type="text/javascript" src="/scripts/test.js"></script>在index.jsp 下如下测试alert(typeof(c()));
但是发现类型是string 好奇怪!!但是我把test.js 写在index.jsp下的话是object 哪里有问题??
scripts
test.js
web-inf
views
index.jsp我的test.js 写了如下函数。返回值是一个对象
var c=function(){
return {
a:'bbb'
};
};我在index.jsp 下面如下导入的
<script type="text/javascript" src="/scripts/test.js"></script>在index.jsp 下如下测试alert(typeof(c()));
但是发现类型是string 好奇怪!!但是我把test.js 写在index.jsp下的话是object 哪里有问题??
这种应该可以实现你的要求:
function(){
var map = {a:'bbb'};
return map;
}
function c(){
return {a:'bbb'};
};
Object map = {a:'bbb'};
return map;
}
还有'bbb'不是String类型,楼主觉得他是什么类型呢
路径写得有问题,应该为:
<script type="text/javascript" src="scripts/test.js"></script>