jQuery append()在所有其他元素之前添加元素(jQuery append() adds element before all others)

编程入门 行业动态 更新时间:2024-10-27 18:27:47
jQuery append()在所有其他元素之前添加元素(jQuery append() adds element before all others) <div style="width: 100%; height: 50%;"> Enter URL: <input id="addressText" type="text" style="width: 60%;"/> <input id="sendRequestButton" type="button" value="Get"/> </div> <div id="container" style="width: 100%; height: 50%;"></div>

后来,我有:

$(document).ready(function() { $("#sendRequestButton").click(function() { $("#container").append("Blablabla"); } }

出于某种原因,新文本出现在页面上的每个其他元素之前! 这是什么原因,我该如何解决? 谢谢。

<div style="width: 100%; height: 50%;"> Enter URL: <input id="addressText" type="text" style="width: 60%;"/> <input id="sendRequestButton" type="button" value="Get"/> </div> <div id="container" style="width: 100%; height: 50%;"></div>

Later, I have:

$(document).ready(function() { $("#sendRequestButton").click(function() { $("#container").append("Blablabla"); } }

For some reason, the new text appears before every other element on the page! What's the reason for that and how can I fix it? Thanks.

最满意答案

奇怪的是,你的代码很适合。 你确定没有其他的id="container"吗?

$("#sendRequestButton").click(function(){
  $("#container").append("Blablabla");
}); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div style="width: 100%; height: 50%;">
    Enter URL: <input id="addressText" type="text" style="width: 60%;"/>
    <input id="sendRequestButton" type="button" value="Get"/>
</div>
<div id="container" style="width: 100%; height: 50%;"></div> 
  
 

Strange, that works well with your code. Are you sure to not have an other id="container" somewhere?

$("#sendRequestButton").click(function(){
  $("#container").append("Blablabla");
}); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div style="width: 100%; height: 50%;">
    Enter URL: <input id="addressText" type="text" style="width: 60%;"/>
    <input id="sendRequestButton" type="button" value="Get"/>
</div>
<div id="container" style="width: 100%; height: 50%;"></div> 
  
 

更多推荐

div>,id,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-08-05 04:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   append   jQuery   adds   element

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!