[英]dynamically add table row in HTML Table in Javascript
I have following code: 我有以下代码:
<body onload="LoadData()">
<table id="myTable">
</table>
</body>
And I have Javascript function like : 我有像这样的Javascript函数:
<script type="text/javascript">
function LoadData()
{
var sTempTableRow='<tr><td>cell-1 </td><td>cell-2 </td><td>cell-3 </td><td>cell-4 </td></tr>'
$('#myTable').append(sTempTableRow);
}
</script>
I have tried numerous times and at all the times face an exception like Microsoft JScript runtime error: Object expected
. 我已经尝试了无数次,而且每次都遇到
Microsoft JScript runtime error: Object expected
类的异常Microsoft JScript runtime error: Object expected
。
Please tell me what is the problem here. 请告诉我这里是什么问题。
Instead if the onload event use jquery's ready: 相反,如果onload事件使用jquery的ready:
<script type="text/javascript">
$(document).ready(function()
{
var sTempTableRow='<tr><td>cell-1 </td><td>cell-2 </td><td>cell-3 </td><td>cell-4 </td></tr>';
$('#myTable').append(sTempTableRow);
});
</script>
<body>
<table id="myTable">
</table>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.