0

这个查询给了我一个来自数据库的列表

while($res=mysql_fetch_array($temp)){                   
    echo "<tr>";
    echo "<td id='copyme'>".$res['name']."</td>";
    echo "<td><a href=''>Edit</a></td>";                        
}
echo "</tr>";

通过单击编辑,我希望将名称写入此输入框中,以便我可以更新或删除它,一旦名称出现在框中,sql 更新查询就可以工作,我唯一的问题是一旦我单击编辑就可以在那里获取名称。

 <label>Template name:</label> <input id="temp_edit" type="text" name="tempname" />

id 如何通过 jquery 做到这一点?或者,还有更好的方法?

4

1 回答 1

3

copyme用作 a class,而不是 an因为如果id您有来自数据库的列表,您将拥有多个该元素,然后试试这个:

$('#yourTable').on('click', 'a', function(){
    var copyValue = $('.copyme', $(this).closest('tr')).text();
    $('#temp_edit').val(copyValue);
});
于 2013-06-07T01:30:25.377 回答