背景資料:jQuery的 - 用選擇找一個href
我試圖找到在一個href屬性「ROW_ID」的值。當用戶點擊「保存更改」按鈕/圖像時,會觸發該邏輯的是什麼。
問題描述
jQuery代碼我已現在正在返回第二小區,而不是一個在它與HREF的內容。因此,從下面的HTML示例代碼,我需要從
"<a href="index.php?page=row&row_id=21586">Row SAA:HH1</a>"
HTML代碼
觸發jquery的邏輯是在該行的第四單元中的按鈕提取21586,並且ROW_ID是在在第5個單元格中的href。
<tr>
<td id="21581">
<img src="?module=chrome&uri=pix/tango-user-trash-16x16-gray.png" title="1 rack(s) here" height="16" width="16" border="0">
</td>
<td><div id="location_name">SAA:HH-123</div></td>
<td><div id="row_name">SAA:HH1</div></td>
<td>
<input tabindex="1" name="edit" class="edit" src="?module=chrome&uri=pix/pencil-icon.png" id="21581" title="Edit row" type="image" border="0">
<input tabindex="1" style="display: none;" name="submit" class="icon" src="?module=chrome&uri=pix/tango-document-save-16x16.png" title="Save changes" type="image" border="0">
</td>
<td>
<a href="index.php?page=row&row_id=21586">Row SAA:HH1</a>
</td>
</tr>
jQuery代碼
//save button handler
$(".icon").click(function(e){
//find the <a href that has the row id embbeded in it
var row_id = $(this).parent().siblings().children($('a[href$="row_id"]'));
console.log($(row_id).text());
});
任何建議,將不勝感激。
你爲什麼不分析你的ID HREF? –
@YaWang我需要先通過jquery「找到」href ...然後我可以解析它 – dot
在jQuery中'$ ='表示*「以*結尾,但href不以'row_id'結尾,它以'row_id = 21586'結尾。你是否在尋找一個過濾器來匹配密鑰和任何數字,或者你只是想找到那個數字,或者是什麼,它不是很清楚? – adeneo