2011-01-10 56 views
0

的jQuery插件,即時通訊使用的是這種 http://code.google.com/p/jquery-in-place-editor/如何添加動態PARAM

,如果我有這樣

<table> 
<thead> 
<tr> 
<th>id</th> 
<th>first name </th> 
<th>last name </th> 
</tr> 
</thead> 

<tbody> 
<tr> 
<td class="id">1</td> 
<td class="fname">sarmen</td> 
<td class="lname">mikey</td> 
</tr> 

<tr> 
<td class="id">2</td> 
<td class="fname">john</td> 
<td class="lname">angelo</td> 
</tr> 

<tr> 
<td class="id">3</td> 
<td class="fname">sarmen</td> 
<td class="lname">grande</td> 
</tr> 
</tbody> 
</table> 

和我的js表看起來是這樣的

$("td.fname").editInPlace({ 
    url: 'ajax.php', 
    params: '', 
    show_buttons: true   
}); 

然後讓我說我點擊第一條記錄來編輯它是撒旦的名字。我怎麼能傳遞一個參數,只有id 1?因爲如果我這樣做的查詢可以說

"update tbl_users set fname = '$_POST['update_value']' where fname = '$_POST['original_html']'" 

(注:我只是顯示一個例子所以沒有需要清理的帖子,如果這是困擾你的:))

如果我運行此查詢的FNAME sarmen將更新兩條記錄,而不是一條記錄。我怎樣才能更新爲1的ID是隻更新一個記錄。

回答

1
$("table tr").each(function(i, el) { 

    var tdId = $(el).find("td.id"); 

    $(this).find("td.fname".editInPlace({ 
     url: 'ajax.php', 
     params: 'id=' + $(tdId).text(), 
     show_buttons: true    
    }); 

}); 
+0

這是正確的方式!沒有注意到它不是一個功能;) – mekwall 2011-01-10 13:47:28

0

您必須從行中的第一個單元格添加參數ID。

$("td.fname").editInPlace({ 
    id = $(this).parents('tr').children('td:first-child').html(); 
    url: 'ajax.php', 
    params: {id:id}, 
    show_buttons: true   
    }); 

$id = (int)$_POST['id'];在PHP