二维数组 forEach table 获取坐标 JTSL,JAVASCRIPT
2D Array forEach table getting coordinates JTSL, JAVASCRIPT
我得到了一个字符串[][],这是我玩的table(编码战舰)。我这样显示:
<%
String[][] field2 = master.getField(2);
request.setAttribute("field", field2);
%>
<div class=feldbeschreibung>Gegnerisches Feld</div><div class=feldbeschreibung2>Dein Feld</div>
<table class=player_field2>
<tbody>
<c:forEach items="${field}" var="row">
<tr>
<c:forEach items="${row}" var="item">
<td class="tdBox" onclick="attack(this, x, y)">
<span>${item}</span>
</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
我想要的是让我的方法 attack() <-javascript 在我点击的坐标上。我可以像这样调用方法本身:但我缺少我正在单击的坐标。顺便说一句,我对 Java、Javascript、JSP 和 JTSL(所有这些都已使用)还很陌生。
提前致谢:)
这是演示代码。
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<c:set var="filler" value="x,x,x,x,x,x,x,x,x,x"/>
<c:set var="field" value="${[filler,filler,filler,filler,filler,filler,filler,filler,filler,filler]}"/>
<html>
<body>
<table>
<tbody>
<c:forEach items="${field}" var="row" varStatus="xStatus">
<tr>
<c:forEach items="${row}" var="item" varStatus="yStatus">
<td style="border: 1px solid black;">${xStatus.count}:${yStatus.count}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
我得到了一个字符串[][],这是我玩的table(编码战舰)。我这样显示:
<%
String[][] field2 = master.getField(2);
request.setAttribute("field", field2);
%>
<div class=feldbeschreibung>Gegnerisches Feld</div><div class=feldbeschreibung2>Dein Feld</div>
<table class=player_field2>
<tbody>
<c:forEach items="${field}" var="row">
<tr>
<c:forEach items="${row}" var="item">
<td class="tdBox" onclick="attack(this, x, y)">
<span>${item}</span>
</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
我想要的是让我的方法 attack() <-javascript 在我点击的坐标上。我可以像这样调用方法本身:但我缺少我正在单击的坐标。顺便说一句,我对 Java、Javascript、JSP 和 JTSL(所有这些都已使用)还很陌生。
提前致谢:)
这是演示代码。
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<c:set var="filler" value="x,x,x,x,x,x,x,x,x,x"/>
<c:set var="field" value="${[filler,filler,filler,filler,filler,filler,filler,filler,filler,filler]}"/>
<html>
<body>
<table>
<tbody>
<c:forEach items="${field}" var="row" varStatus="xStatus">
<tr>
<c:forEach items="${row}" var="item" varStatus="yStatus">
<td style="border: 1px solid black;">${xStatus.count}:${yStatus.count}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>