2012-04-24 85 views
0
$.each(thedata.data, function() {  
$('#theReturnFormTable').append(   
'<tr id="newReturn"><td align="center"><a href="##" id="link">'+ this.newrequestor 
+'<input type="hidden" id="theID" value="'+ this.theid +'"></a></td><td 
align="center">'+ this.newthedate +'</td><td>'+ this.theid +'</td><td 
align="center">'+ this.newapproved +'</td> 
<td align="center">'+ this.newsecurityaction +'</td></tr>' 
); 
}); 

結果:的jQuery通過唯一的ID不形

requestor=dave theID = 75 
requestor=frank theID = 76 
requestor=bill theID = 77 
requestor=george theID = 78 
requestor=sam theID = 79 and so on. 

我的每一行中的鏈接,它抓住theID = 75,無論行我點擊,而不是通過theID的值該行的。我有腦凍結。任何想法如何傳遞每行的ID的值?

這裏就是我通過theID到

$("#link").live("click", function(){ 
//show layer Div 
$("#theHover").show(); 
alert($("#theID").val()); 
var instance = new readers_cls(); 
var theID = $("#theID").val(); 

newdata = instance.getRequestSecurity(theID); 
newrooms = instance.getRequestSecurityRooms(theID); 
newcust = instance.getRequestSecurityCust(theID); 

我知道它只是下降的頁面,並抓住在HTML中的第一theID。我需要找出解決辦法。

+0

你可以創建一個小提琴嗎? – Celos 2012-04-24 16:02:21

+0

你將最終在文檔中出現重複的「id」。這將導致問題。 – 2012-04-24 16:04:33

+0

從來沒有這樣做 – user1253239 2012-04-24 16:06:09

回答

0

您正在創建多個元素,其ID爲'theID',從您發佈的第一個循環開始,這並不好。你爲什麼不創建一個適當的ID的元素在那裏,然後,使:

$.each(thedata.data, function() {  
    $('#theReturnFormTable').append(   
    '<tr id="newReturn"><td align="center"><a href="##" id="link">'+ this.newrequestor 
    +'<input type="hidden" id="id_'+this.theid'" value="'+ this.theid +'"></a></td> 
    ... 
    ); 
}); 

這樣,所有隱藏的輸入元素將有一個uniqui id,這將你以後拿起...

+0

id =「id _'+ this.theid'」確實創建了唯一的ID,但是如何在點擊鏈接時抓住這個ID? – user1253239 2012-04-24 16:18:59