JS中<img><a>获取绝对路径

来源:互联网 发布:云计算和数据中心 编辑:程序博客网 时间:2024/05/21 06:39

【不定期更新】

先在页面文档中定义

<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>

<body data="${pageContext.request.contextPath}">
当然,这个data不一定要赋给body,赋给其他标签也是一样的

然后,在JS中就可以调这个data了

<img src='+getPath()+'/WeChat/images/shopping_car_little.jpg />


0 0
原创粉丝点击