我有一個網頁,並使用PHP進出口查詢一個數據庫中的表像這樣顯示結果:Jquery - 每行特定的訪問變量?
<table id="tablelist">
<thead>
<tr>
<th>Header1</th>
<th>Header2</th>
<th>Header3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Info here1</td>
<td>Info here1</td>
<td class="actions">Action1 - Action2 - Action3</td>
</tr>
<tr>
<td>Info here2</td>
<td>Info here2</td>
<td class="actions">Action1 - Action2 - Action3</td>
</tr>
</tbody>
</table>
現在每一行都有特定於該行是從數據庫中是唯一的信息。例如,主要ID,日期和類別。當有人點擊任何行的操作時,我需要獲得這些特定於他們所點擊行的2條信息。目前,我試着這樣做:
<div class="row_data">{info2 in json format}</div>
<tr>
<td>Info here1</td>
<td>Info here1</td>
<td class="actions">Action1 - Action2 - Action3</td>
</tr>
<div class="row_data">{info2 in json format}</div>
<tr>
<td>Info here2</td>
<td>Info here2</td>
<td class="actions">Action1 - Action2 - Action3</td>
</tr>
因此,當有人動作鏈接點擊它會得到ROW_DATA的前值,這是JSON格式。我會使用jquery來解析json值並使用jquery代碼其餘部分中找到的信息。但我被告知這是無效的HTML,不推薦。當一個動作被點擊時,什麼會是一個推薦的/最佳的故事動態數據每行的使用方式,以便我可以在我的jQuery代碼中引用它?
但如果我有id =「foo」每行不是不是?在頁面上有重複的ID? – John
@John:當然。那只是一個例子。您也可以執行'$(this).closest(「tr」)。data(...)'或選擇將屬性完全放在其他元素上。 – Jon
建議使用data- {name}屬性不要爲所有id使用foo –