我想在html table中替换。有人帮我 请检查下面的代码
<html>
<head>
<script type="text/javascript">
function changeRows()
{
var htmlString="<tr><td>bhanu</td><td>s</td></tr>";
$("#myTable tbody").html(htmlString);
}
</script>
</head>
<body>
<table id='myTable'>
<thead>
<tr>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
<tr>
<td>hari</td>
<td>y</td>
</tr>
</tbody>
</table>
<button onClick='changeRows()'>changText</button>
</body>
</html>
我的myTable tbody
没有html的方法
答案 0 :(得分:1)
<强>替换强>
onClcik='changeRows'>
<强>与强>
onClick='changeRows();'>
更改 fucntion
function
<script type="text/javascript">
function changeRows()
{
var htmlString = "<tr><td>bhanu</td><td>s</td></tr>";
$("#myTable tbody").html(htmlString);
}
</script>
答案 1 :(得分:0)
更改:
fucntion changeRows()
要:
function changeRows()
并改变:
<button onClcik='changeRows'>changText</button>
要:
<button onclick='changeRows()'>changText</button>
答案 2 :(得分:0)
首先把这里正确的代码放在....... 您可以用下面的代码替换您的代码......
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
function changeRows(){
var htmlString="<tr><td>bhanu</td><td>s</td></tr>";
$("#myTable tbody").html(htmlString);
}
</script>
</head>
<body>
<table id='myTable'>
<thead>
<th>
<td>FirstName</td>
<td>LastName</td>
</th>
</thead>
<tbody>
<tr><td>hari</td><td>y</td></tr>
</tbody>
</table>
<button onclick="changeRows()" >changText</button>
</body>
</html>
答案 3 :(得分:0)
我的建议如下:Fiddle for this
<table id='myTable'>
<thead>
<th>
<td>FirstName</td>
<td>LastName</td>
</th>
</thead>
<tbody>
<tr>
<td>hari</td>
<td>y</td>
</tr>
</tbody>
</table>
<button onClick='changeRows()'>changText</button>
然后在head部分添加这个库:
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script>
function changeRows() {
//-^^^^^^^----------------------spell it correctly too
var htmlString = "<tr><td>bhanu</td><td>s</td></tr>";
$("#myTable tbody").html(htmlString);
}
</script>
看到这个:
onClick='changeRows()'
^^^^^^^-------------------spell it correctly