jsp,css,js中变量的传递关系
2017-04-26 16:20
246 查看
一。从controller中传值到js页面,是不能像传到jsp页面那样直接接收,而要采用间接的传值:
1。由uil,请求: localhost:+'/bdmap?lat='+point.lat+'&lng='+point.lng;
2。controller中接收:
@GetMapping("bdmap")
public ModelAndView police(@RequestParam Map<String, Object> map ){
return new ModelAndView("mapBD/list").addObject("map", map);
}
3。页面间接接收:
需要在html中引入:<html xmlns:th="http://www.thymeleaf.org">
<body>
<div style=display:none;>
<input id="map_lat" th:value="${map.lat}" />
<input id="map_lng" th:value="${map.lng}" />
</div>
</body>
4。在js中获取控件的值:
var maplat = $("#map_lat").val();
var maplng = $("#map_lng").val();
if( maplat == "undefined" || maplng == "undefined"){
}
注意:在html中获取的值为空时,在js中取到的值时“undefined”,而不是undefined。
二,jsp中的js与加载的js文件中的js运行的先后次序与js文件加载的位置有关,在前的先运行。
三,jsp中变量与js文件中变量,若js中要用到jsp中文件的变量,则必须在js文件之前先运行并且要设为公用变量,反过来,如果jsp中要使用js中的文件变量,则要等到js文件加载完菜能使用。
如:
<script>
var plate = "<%=plate%>";
</script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/appraise.js">
</script>
则,appraise需等上面代码运行完后再加载,所以apprraise.js中可使用plate变量。
<script type="text/javascript" src="<%=request.getContextPath()%>/js/appraise.js">
</script>
<script>
var plate = "<%=plate%>";
</script>
则,appraise在上面代码运行之前就加载了,所以apprraise.js中不可使用plate变量。
1。由uil,请求: localhost:+'/bdmap?lat='+point.lat+'&lng='+point.lng;
2。controller中接收:
@GetMapping("bdmap")
public ModelAndView police(@RequestParam Map<String, Object> map ){
return new ModelAndView("mapBD/list").addObject("map", map);
}
3。页面间接接收:
需要在html中引入:<html xmlns:th="http://www.thymeleaf.org">
<body>
<div style=display:none;>
<input id="map_lat" th:value="${map.lat}" />
<input id="map_lng" th:value="${map.lng}" />
</div>
</body>
4。在js中获取控件的值:
var maplat = $("#map_lat").val();
var maplng = $("#map_lng").val();
if( maplat == "undefined" || maplng == "undefined"){
}
注意:在html中获取的值为空时,在js中取到的值时“undefined”,而不是undefined。
二,jsp中的js与加载的js文件中的js运行的先后次序与js文件加载的位置有关,在前的先运行。
三,jsp中变量与js文件中变量,若js中要用到jsp中文件的变量,则必须在js文件之前先运行并且要设为公用变量,反过来,如果jsp中要使用js中的文件变量,则要等到js文件加载完菜能使用。
如:
<script>
var plate = "<%=plate%>";
</script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/appraise.js">
</script>
则,appraise需等上面代码运行完后再加载,所以apprraise.js中可使用plate变量。
<script type="text/javascript" src="<%=request.getContextPath()%>/js/appraise.js">
</script>
<script>
var plate = "<%=plate%>";
</script>
则,appraise在上面代码运行之前就加载了,所以apprraise.js中不可使用plate变量。
相关文章推荐
- js变量与jsp中变量的相互传递
- JS与VBS传递变量
- 解决在url中传递js变量到java程序中出现乱码问题(转自http://www.blogjava.net/fine)
- 我理解c#(一): 参数传递和变量复制之间的关系
- js调用flash中的方法,让flash传递变量给js
- js jsp 交互 js与jsp的数据交互 js向jsp中传递数据 jsp向js中传递数据 js向jsp传递数组
- js如何取得网址中传递的变量的值
- 简谈HTML、CSS、JavaScript、Ajax、WML、Servlet、Jsp、FreeMarker、Velocity、Webmacro是什么,以及之间的关系!
- js、jsp传递参数乱码问题解决
- flash调用js中的方法,让js传递变量给flash (兼容 IE & FF)
- 在Eclipse里面使用其它编辑器打开jsp,css,js等文件
- js如何取得网址中传递的变量的值
- Eclipse关联源码,Dreamweaver代码提示失效,js调用jsp中的变量
- 页面加入_JS,CSS使用,#include添加文件,缓存页面,页面间传递汉字,IsPostBack控制页面的加载,自定义错语页面
- flash调用js中的方法,让js传递变量给flash (兼容 IE & FF) (转)
- 如何把JS的变量的值传递给PHP的变量啊?
- javascipt,js文件如何调用jsp变量
- js调用flash中的方法,让flash传递变量给js
- jsp引入js,css文件的方法
- 怎么将JS里面的变量传递到PHP里面去