2016-03-30 10 views
0

私は演奏テーブル(コード化された戦艦)であるString [] []を取得しました。 - 私はクリックてる座標何のjavascriptの2D配列for eachテーブルの座標を取得するJTSL、JAVASCRIPT

<% 
    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> 

This is how it looks

私が欲しいん何<)(私のメソッドの攻撃をさせることです:私はこのようにそれを表示します。私はこのようにメソッド自体を呼び出すことができます:しかし、私はどの座標をクリックしているのか分かりません。 Btw私はJava、Javascript、JSP、JTSL(これはすべて使用されています)にはかなり新しいです。

ありがとうございました:)

+0

forEachタグで使用できる属性であるvarStatus = "xStatus"を使用できます。それを使用すると、onclick = "attack(this、$ {xStatus.count}、$ {yStatus.count})"のようなものを使うことができます。 – rickz

+0

それは、ありがとう! :) – Selias

答えて

0

デモンストレーションコードです。

<%@ 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> 
関連する問題