Javascript 如何使用jQuery引用表行
下午, 我希望将表的行号传递给函数,以引用该特定表中的特定行,例如,假设我有:Javascript 如何使用jQuery引用表行,javascript,jquery,html,Javascript,Jquery,Html,下午, 我希望将表的行号传递给函数,以引用该特定表中的特定行,例如,假设我有: <table id="foo"> <tr><td>some stuff...</td><tr> <tr><td>stuff</td><tr> <tr><td>more stuff</td><tr> <tr><td>some
<table id="foo">
<tr><td>some stuff...</td><tr>
<tr><td>stuff</td><tr>
<tr><td>more stuff</td><tr>
<tr><td>some stuff</td><tr>
<tr><td>some stuff</td><tr>
</table>
这就是我的全部功能
function manipulateRow(rowIndex){
/* do something */
}
如何将rowIndex参数引用到函数中的表?例如:
$('#foo').child("tr")[rowIndex].html('<td>i now contain even more stuff!</td>'); // I know this is wrong, how do I make it right?
$('#foo').child(“tr”)[rowIndex].html(“我现在包含更多的东西!”);//我知道这是错误的,我怎样才能使它正确?
抱歉,如果我说得有点含糊不清或者没有解释清楚自己的意思。这实际上只能像这样工作:
$($('#foo tr')[rowIndex]).html('<td>i now contain even more stuff!</td>');
$($('#foo tr')[rowIndex]).html('我现在包含更多的东西!');
但最好使用:eq简单
$("#foo tr:eq("+rowIndex+")").html("<td>i now contain even more stuff!</td>");
$(“#foo tr:eq(“+rowIndex+”)).html(“我现在包含了更多的东西!”);
在这里了解有关jQuery选择器的更多信息:试试这个
$('#foo > tr').eq(rowIndex).html('<td>i now contain even more stuff!</td>');
$('#foo>tr').eq(rowIndex.html('我现在包含更多的东西!');
请参阅。给您:
<table>
<tbody>
<tr><td>Foo</td></tr>
</tbody>
<tfoot>
<tr><td>footer information</td></tr>
</tfoot>
</table>
$("#myTable > tbody").append("<tr><td>row content</td></tr>");
福
页脚信息
$(“#myTable>tbody”).append(“行内容”);
以下是另一个内联编辑示例:
function editRow(row) {
$('td',row).each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" />');
});
}
函数编辑行(行){
$('td',行)。每个(函数(){
$(this.html(“”);
});
}
正是我想要的!谢谢!
<table>
<tbody>
<tr><td>Foo</td></tr>
</tbody>
<tfoot>
<tr><td>footer information</td></tr>
</tfoot>
</table>
$("#myTable > tbody").append("<tr><td>row content</td></tr>");
function editRow(row) {
$('td',row).each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" />');
});
}