0
私は単純なテーブルを持っています。特定の行をクリックした後にその行にincidentId
の値を取得し、隠し空変数に代入します。行のjqueryを使用してテーブルのセル値を取得する
私のテーブル
<table class="table table-striped">
<thead style="background-color: #F0F1F2">
<tr>
<th>Incident Id</th>
<th>Party Name</th>
<th>Max Rank</th>
<th>Incident Description</th>
</tr>
</thead>
<tbody>
<c:forEach items="${incidents}" var="incident">
<tr onclick="changeIncidentValue(this)">
<td>${incident.incidentId}</td>
<td>xxx</td>
<td>${incident.partyNameMaxRank}</td>
<td>${incident.incidentDesc}</td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="hidden" id="incidentId" value=""/>
JS機能
<script>
function changeIncidentValue(incidentId){
$('#incidentId').val(incidentId);
console.log($('#incidentId').val());
}
</script>
uは何かを試してみました?あなたのjqueryコードはどこですか? –
質問が更新されました – Casper
答えて
ハンドラ
代わりの
をクリックインライン化するincidentId
の代わりthis
を渡しますそれとも、あなたが
this
を渡しているように、第一のカラムからincidentId
を取得するために、最初のTD要素出典
2017-06-13 11:20:00 Satpal
使用find()とeq()から値を取得するには、DOMのトラバーサル方法でそれを使用し、
また、incidentIdの値onclickイベントを直接設定することもできます。
出典
2017-06-13 11:20:16
これを試しても意味がありません。 –
https://jsfiddle.net/ew73yjaa/
jQueryの
HTML
出典
2017-06-13 11:32:15
関連する問題