2016-08-09 21 views
1

私は、リストを反復処理し、Beanを使用して値を表示しています:書き込み、私は私の行の詳細をキャプチャするONFOCUSイベントを使用してなど特定の行から値を取得することができません。<ロジック:反復>

コードの何かを使用していますこれは:

<logic:iterate id="empList" name="search" property="empList" indexId="index"> 
     <tr> 
      <td> 
       <span id="empid"><bean:write name="empList" property="empID"/></span> 
      </td> 

      <td> 
       <bean:write name="empList" property="firstName"/> 
      </td> 

      <td> 
       <bean:write name="empList" property="lastName"/> 
      </td> 

      <td> 
       <html:button property="View" value="View" onfocus="viewPage()"/>   
      </td> 
     </tr> 
</logic:iterate> 


<script> 
function viewPage(){ 
var empid = document.getElementByID("empid).innerHTML; 
} 
</script> 

が、私はそれがD寿getElementId()で、 変数は、あなたが間違った関数名を使用するようだ

+0

[__Thereは、同じ 'id'の値を持つ' document'内の複数の 'elements'であってはなりません.___](https:// www .w3.org/TR/html-markup/global-attributes.html#common.attrs.id) – Rayon

答えて

0

を助けてください、私のJavaScriptでEMPID値を取得することはできませんよあなたが二重引用符を閉じないようにしてください。

使用この

var empid =document.getElementById("empid").innerHTML;

https://jsfiddle.net/cLL70bmq/

0

= "true" の各フィールドインデックス付けセットとJS

<html:form action="something"> 
    <logic:iterate id="empList" name="search" property="empList" indexId="index"> 
       <tr> 
        <td> 
         <span id="empid"><html:text name="empList" property="empID" styleId="empId" indexed="true"/></span> 
        </td> 

        <td> 
         <bean:write name="empList" property="firstName" indexed="true"/> 
        </td> 

        <td> 
         <bean:write name="empList" property="lastName" indexed="true"/> 
        </td> 

        <td> 
         <html:button property="View" value="View" indexed="true" onfocus="viewPage(<bean:write name='index'/>)"/>   
        </td> 
       </tr> 
     </logic:iterate> 
</html:form> 

に値を取得して、あなたのJSを更新するために、フォーム要素を取ります

<script> 
function viewPage(x){ 
var empid = document.forms[0].empId[x].value; 
} 
</script> 

希望しますこれはあなたに役立ちます

関連する問題