不要切换()只是显示()
$("button#submitid").click(function () {
$("#datatable").append('<tr id="foo"><td>hi</td><td>hi</td><td>hi</td><td>hi</td><td>hi</td><td>hi</td></tr>');
$("#datatable").show();
});
编辑对 OP 评论的回应http://jsfiddle.net/e254w/
// json data object
var data = JSON.parse('{ "1": ["a","b","c"], "2": ["x","y","z"] }');
$("#submitid").click(function() {
var rowId = $("#number").val();
var rowData = data[rowId];
if(rowData) {
var tr = $("<tr></tr>").attr("id", "datatable-row-" + rowId);
for(var col=0; col<rowData.length; col++)
tr.append($("<td></td>").text(rowData[col]));
$("#datatable").append(tr);
$("#datatable").show();
} else {
alert("Row doesn't exist in json object: " + rowId);
}
});