-3

我想在 html 表中替换。任何人帮助我请检查我下面的代码

<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>

我的 myTabletbody没有 html 的方法

4

4 回答 4

1

replace

 onClcik='changeRows'>

with

onClick='changeRows();'>

change fucntion with function

<script type="text/javascript">
function changeRows()
{
    var htmlString = "<tr><td>bhanu</td><td>s</td></tr>";
    $("#myTable tbody").html(htmlString);
}
</script>
于 2013-10-10T09:58:33.960 回答
0

改变:

 fucntion changeRows()

至:

  function changeRows()

并改变:

<button onClcik='changeRows'>changText</button>

至:

<button onclick='changeRows()'>changText</button>
于 2013-10-10T09:59:31.360 回答
0

我的建议是:Fiddle for this

html:

  <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
于 2013-10-10T10:08:30.077 回答
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>
于 2013-10-10T10:02:09.830 回答