今天,做项目中的一个jsp页面,我的需求如下:
我需要将url http://localhost:8080/lgc/index.jsp?mapname=...后面的mapname作为参数获取,
我在JSP的body里面是这样的:
<body onLoad="onPageLoad(<%=request.getParameter("mapname")%>)">
</body>,
然后onPageLoad是JS中的一个函数,我要在onPageLoad(),中得到mapname,
JS中代码:onPageLoad(mapname){alert(mapname)};
一直提示mapname没有定义,郁闷了一天。。。
然后请教了大学一哥们,终于解决啦!
之前我的:http://localhost:8080/lgc/index.jsp?mapname=test是这样写的,
然后哥们给修改了一下:为
http://localhost:8080/lgc/index.jsp?mapname='test';
这样在JS中就可以得到mapname=test啦!爽啊!