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>'
 );
 });

結果:

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

各行にリンクがあり、その行の theID の値を渡す代わりに、クリックした行に関係なく theID = 75 を取得します。私は脳が凍っています。各行の theID の値を渡す方法はありますか?

これが私が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 を取得することはわかっています。これを回避する方法を見つける必要があります。

4

2 に答える 2

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>
     ...
   );
});

このようにして、すべての非表示の入力要素には、後で取得する一意の ID があります...

于 2012-04-24T16:09:27.297 に答える
0

すべての要素に一意ではない ID を与えていることが原因だと思います (そのコードで静的 ID を割り当てているため)。クラスと「this」キーワードを使用します。

于 2012-04-24T16:10:06.800 に答える