Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
Javascript 在动态生成的表之后插入jQuery中的范围_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在动态生成的表之后插入jQuery中的范围

Javascript 在动态生成的表之后插入jQuery中的范围,javascript,jquery,html,Javascript,Jquery,Html,我试图在动态生成的表之后添加一个跨度,但在加载表的内容之前添加了跨度 下面是我的代码: <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ dash();

我试图在动态生成的表之后添加一个跨度,但在加载表的内容之前添加了跨度

下面是我的代码:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    dash();
    $("button").click(function(){
        $("#th").append("<span>span</span>");
    });
});

function dash()
{ 
     $("#hu").html();
     $("#hu").append("<tr> <td> see this </td> </tr>");
}
</script>
</head>
<body>

<button>Insert content after each p element</button>
<div align="right" id="th">
<table id="hu" align="right">
<tr><td>hello</td></tr>
</table>
</div>
</body>
</html>

$(文档).ready(函数(){
破折号();
$(“按钮”)。单击(函数(){
$(“#th”)。追加(“span”);
});
});
函数dash()
{ 
$(“#hu”).html();
$(“#hu”)。追加(“见此”);
}
在每个p元素后插入内容
你好

在hello之前添加跨度。我希望span显示在表内容之后。

您可以这样写
$(“#hu”)。在(“span”)之后


这将把span放在表之后

将span添加到dom的底部。您在表格前面看到它,因为表格是右对齐的。请尝试以下操作:

$(文档).ready(函数(){
破折号();
$(“按钮”)。单击(函数(){
$(“#th”)。追加(“span
”; }); }); 函数dash() { $(“#hu”).html(); $(“#hu”)。追加(“见此”); }

在每个p元素后插入内容
你好


像@Reoxey那样在
函数之后使用jQuery
。但是,请确保在
标记之前添加脚本,而不是在
标记上使用脚本。建议在
标记之前添加Javascript,以防止在加载脚本时出现渲染阻塞,这对SitePerception head更有利。在
标记之前添加Javascript也将提高站点加载速度。

嘿,请尝试一下

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    dash();
    $("button").click(function(){
        $("#hu").append("<span>span</span>");
    });
});

function dash()
{ 
     $("#hu").html();
     $("#hu").append("<tr> <td> see this </td> </tr>");
}
</script>
</head>
<body>

<button>Insert content after each p element</button>
<div align="right" id="th">
<table id="hu" align="right">
<tr><td>hello</td></tr>
</table>
</div>
</body>
</html>

$(文档).ready(函数(){
破折号();
$(“按钮”)。单击(函数(){
$(“#hu”)。追加(“span”);
});
});
函数dash()
{ 
$(“#hu”).html();
$(“#hu”)。追加(“见此”);
}
在每个p元素后插入内容
你好
您应该使用表id,即
#hu
作为
#th

希望这有帮助。:)

只要改变一下:

$("#th").append("<span>span</span>");
$(“#th”)。追加(“span”);
致:

$(“表”)。追加(“span”);
JS Fiddle:

这将对您有所帮助

  $(document).ready(function(){
    dash();
    $("button").click(function(){
        $("#hu").after("<span>span</span>");
    });
  });
$(文档).ready(函数(){
破折号();
$(“按钮”)。单击(函数(){
美元(“#胡”)。在(“span”)之后;
});
});

如果您在hello之后显示此链接,我将显示
的作用是什么
$(“#hu”).html()不允许表使用align=“right”这是因为您使用的是
align
属性。元素被追加,即“hello”之后的“正在添加跨度”。@Vohuman我希望表格向右对齐,跨度也应该向右对齐。。。这就是我使用align attibuteIndeed的原因,但这并不能解决他的问题。你所建议的只是做同样事情的另一种方式。
  $(document).ready(function(){
    dash();
    $("button").click(function(){
        $("#hu").after("<span>span</span>");
    });
  });