Jquery 如何在不使用<;tr>;标签?
我知道如何使用jquery将新行追加到表中。最简单的方法是使用标记Jquery 如何在不使用<;tr>;标签?,jquery,html-table,append,row,Jquery,Html Table,Append,Row,我知道如何使用jquery将新行追加到表中。最简单的方法是使用标记: 函数insertRow(数据,报表编号){ var guid=$(数据).find('ID').text(); var portId=$(数据).find('portId').text(); 变量状态=$(数据).find('status').text(); $('#gvwCashRegisterList')。附加( “”+新日期().ToLocalString()+“”+guid+“”+reportNumber+“”+por
:
函数insertRow(数据,报表编号){
var guid=$(数据).find('ID').text();
var portId=$(数据).find('portId').text();
变量状态=$(数据).find('status').text();
$('#gvwCashRegisterList')。附加(
“”+新日期().ToLocalString()+“”+guid+“”+reportNumber+“”+portId+“”+status+“”
);
}
是否有任何已知的方法可以在不使用标签的情况下执行此操作?例如:jQuery函数、插件或库?只有
标记可以在HTML中生成表行。没有其他方法可以用表中的另一个标记复制它们的行为
不过,有一种更简洁的方法可以附加表行:
$("table tbody").append(
$("<tr>") // create new tr element
.attr("class","newTR") // set its class
.append(
$("<td>") // create a new td element within the tr
.html("But this is new!") // set its content
)
);
$(“表tbody”).append(
$(“”)/创建新的tr元素
.attr(“class”,“newTR”)//设置其类
.附加(
$(“”)/在tr中创建一个新的td元素
.html(“但这是新的!”)//设置其内容
)
);
注意分号的缺乏
代码>(例如,在第二个append()
和html()
之后)。在jQuery中,可以执行以下操作:
$('<tr class="myclass" />')
.append($('<td />').html('whatever here'))
.appendTo('table');
$(“”)
.append($('').html('whichere'))
.附录(“表格”);
使用1.4+语法有一种更简洁的方法:
$("table").append(
// create new tr element
$("<tr></tr>", {
"class": "newClass", // set its class
html: $("<td></td>", { // create a td element within the tr
text: "Table cell" // add text content
})
});
});
$(“表”).append(
//创建新的tr元素
$("", {
“类”:“newClass”,//设置其类
html:$(“”,{//在tr中创建td元素
text:“表格单元格”//添加文本内容
})
});
});
现在,所有内容都整齐地封装在新的tr对象中。属性和内容在传递给$()方法的第二个参数(对象文字)中定义;) 不完全重复,但可能有用:可以在Javascript中使用insertRow函数:)
$("table").append(
// create new tr element
$("<tr></tr>", {
"class": "newClass", // set its class
html: $("<td></td>", { // create a td element within the tr
text: "Table cell" // add text content
})
});
});