Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery追加一个div区域_Jquery - Fatal编程技术网

Jquery追加一个div区域

Jquery追加一个div区域,jquery,Jquery,您好,我想在表格中添加一个新行,每次在我的代码中单击按钮时,下面的代码都可以工作,但我希望它位于名为“选择器”的DIV标记中,作为我表格的一个添加项,但它却出现在页面顶部,请问我做错了什么?谢谢 <script type="text/javascript"> $(document).ready(function(){ $("#test").click(function() { tested(this) });

您好,我想在表格中添加一个新行,每次在我的代码中单击按钮时,下面的代码都可以工作,但我希望它位于名为“选择器”的DIV标记中,作为我表格的一个添加项,但它却出现在页面顶部,请问我做错了什么?谢谢

        <script type="text/javascript">
            $(document).ready(function(){
              $("#test").click(function() { tested(this) }); 
            });


            function tested() {

            newline = "<tr bgcolor='#666666'><td>&nbsp;</td>  <td><input type='button' id='test1'  value='Click to Test' /></td><td>&nbsp;</td>  </tr> " ;

            $('#selector').append(newline)
            }

        </script> 

            <table width="500" border="1" cellspacing="1" cellpadding="1" bgcolor="#CCCCCC" align="center">
              <tr>
                <td width="50">top</td>
                <td>&nbsp;</td>
                <td width="50">&nbsp;</td>
              </tr>

             <div id='selector' > 
              <tr bgcolor="#666666">
              <td>&nbsp;</td>
              <td><input type="button" id="test"  value="Click to Test" /></td>
              <td>&nbsp;</td>
              </tr>
              </div>

              <tr>
                <td>Bottom</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>

            </table>

            </body>
            </html>

$(文档).ready(函数(){
$(“#测试”)。单击(function(){tested(this)});
});
功能测试(){
新行=”;
$(“#选择器”).append(换行符)
}
顶部
底部

您的代码不是有效的html-这必然会在不同的浏览器中导致意外行为

不能将
div
标记包含为
表的直接子项
-为此,请使用
tbody

<table width="500" border="1" cellspacing="1" cellpadding="1" bgcolor="#CCCCCC" align="center">
    <thead>
          <tr>
            ...
          </tr>
    </thead>
    <tbody id='selector' > 
          ...
    </tbody>
</table>

...
...

您的代码不是有效的html-这必然会在不同的浏览器中导致意外行为

不能将
div
标记包含为
表的直接子项
-为此,请使用
tbody

<table width="500" border="1" cellspacing="1" cellpadding="1" bgcolor="#CCCCCC" align="center">
    <thead>
          <tr>
            ...
          </tr>
    </thead>
    <tbody id='selector' > 
          ...
    </tbody>
</table>

...
...

为什么要将其传递给函数调用,但没有参数。。。您应该在tested中使用一个参数,并在jQuery选择器中使用它。为什么要将它传递给函数调用,但没有参数。。。您应该在tested中使用一个参数,并在jQuery选择器中使用该参数。谢谢Dexter,我将复习一下我的html!谢谢Dexter,我会复习我的html!