2011-01-10 79 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