2013-07-04 46 views
1

此代碼具有可能從@COntroller填充的一些值,我只想選擇一個複選框,並將該行轉換爲文本框。通過使用此代碼,只有第一行變爲文本框。我如何使用jstl genarate動態複選框值

<table border=2> 
<th>ID</th><th>Status</th><th>test</th><th>Name</th><th><input type="button" name="edit"  value="Edit" onclick="setEditable(this)"> </th> 

<c:forEach items="${Data}" var="data"> 
<tr> <td> 
<input type="text" disabled="disabled" id="idc" value=" ${data.ID}"> </td> 
<td><input type="text" disabled="disabled" id="status" value="${data.status}"></td> 
<td><input type="text" disabled="disabled" id="test" value="${data.test}"></td> 
<td><input type="text" disabled="disabled" id="name" value="${data.Name}"></td> 
<td><input type="checkbox" name="Rowselect" onclick="setEditable(this)" ></td> 
</tr> 
    </c:forEach> 
    </table> 

    <script type="text/javascript"> 
    function setEditable() 
    { 
     document.getElementById("idc").disabled = false; 
     document.getElementById("status").disabled = false; 
     document.getElementById("test").disabled = false; 
     document.getElementById("name").disabled = false; 
      alert("after the remove"); 

    } 
    </script> 
+0

你得到的答案? – Sri

回答

0
<table border=2> 
    <th>ID</th> 
    <th>Status</th> 
    <th>Test</th> 
    <th>Name</th> 
    <th>Select</th> 
    <c:forEach items="${Data}" var="data" varStatus="stCount" begin="0" 
     end="${Data.size()}"> 
     <tr> 
      <td><input type="text" disabled="disabled" 
       id="itc${stCount.count}" value=" ${data.ID}"></td> 
      <td><input type="text" disabled="disabled" 
       id="status${stCount.count}" value="${data.status}"></td> 
      <td><input type="text" disabled="disabled" 
       id="test${stCount.count}" value="${data.test}"></td> 
      <td><input type="text" disabled="disabled" 
       id="name${stCount.count}" value="${data.Name}"></td> 
      <td><input type="checkbox" id="selectCheck" name="Rowselect" 
       onclick="setEditable('${stCount.count}',this)"></td> 
     </tr> 
    </c:forEach> 
</table> 

<script type="text/javascript"> 
    function setEditable(stCount, event) { 

     if (event.checked) { 
      document.getElementById("idc" + stCount).disabled = false; 
      document.getElementById("status" + stCount).disabled = false; 
      document.getElementById("test" + stCount).disabled = false; 
      document.getElementById("name" + stCount).disabled = false; 
     } else { 
      document.getElementById("itc" + stCount).disabled = true; 
      document.getElementById("status" + stCount).disabled = true; 
      document.getElementById("test" + stCount).disabled = true; 
      document.getElementById("name" + stCount).disabled = true; 
     } 
    } 
</script>