通过a标签向后台传递参数
首先a标签规定,a标签向后台传递的参数必须是定值,例如:<a href="index.html?age=11">跳转</a>如果你这样写的话,它无法识别age:<a href="index.html?age="+age>跳转</a>//或者<a href="index.html?age="+${name}>跳转<...
·
首先a标签规定,a标签向后台传递的参数必须是定值,例如:
<a href="index.html?age=11">跳转</a>
如果你这样写的话,它无法识别age:
<a href="index.html?age="+age>跳转</a>
//或者
<a href="index.html?age="+${name}>跳转</a>
但是在工作中我们需要页面在跳转的时候,还有携带参数,那么我们就需要jQuery来帮助我们来完成了:
<a href="#" id="toUserIndex">首页</a>
<script type="text/javascript">
$(document).ready(function(){
var username="[[${username}]]";
$("#toUserIndex").click(function(){
$("#toUserIndex").attr("href","/user/index/"+username);
});
});
</script>
这样就可以实现a标签动态的向后台传输数据了.
我后台模板引擎用的是thymeleaf,所以获取js数据的时候用的是[[${username}]].
更多推荐
已为社区贡献1条内容
所有评论(0)