JSP 向 JavaScript 中传递数组
采用隐藏标签的方式:
// JSP:
<%
while(rs.next())
{
%>
<input name="store_name" type="hidden" value="<%=rs.getString("store_name")%>"/>
<input name="store_position" type="hidden" value="<%=rs.getString("position")%>"/>
<%
}
}
%>
//javascript 取值:
<div id="mapContainer"></div>
<script type="text/javascript">
var store_des = document.getElementsByName("store_name")
var store_pos = document.getElementsByName("store_position");
for(var i=0;i<store_des.length;i++)
{
var title = store_des[i].value;
var pos =store_pos[i].value;
}
</script>