html中的按钮不使用jquery主体对象呈现
当我在html中插入一个按钮时,它不是呈现。我很确定这与我拥有的jquery body对象有关。如果您能解释一下这里发生了什么以及为什么按钮不会显示,那将非常有帮助html中的按钮不使用jquery主体对象呈现,jquery,html,Jquery,Html,当我在html中插入一个按钮时,它不是呈现。我很确定这与我拥有的jquery body对象有关。如果您能解释一下这里发生了什么以及为什么按钮不会显示,那将非常有帮助 <body> <div id="container"> <button class="newTweets">More Tweets!</button> </div> <script> $(document).r
<body>
<div id="container">
<button class="newTweets">More Tweets!</button>
</div>
<script>
$(document).ready(function(){
var $body = $('body');
$body.html('<h1></h1>'); //h1 tags before
var index = streams.home.length - 1;
while(index >= 0){
var tweet = streams.home[index];
var $tweet = $('<div></div>');
$tweet.text('@' + tweet.user + ': ' + tweet.message);
$tweet.appendTo($body);
index -= 1;
}
});
</script>
</body>
更多推特!
$(文档).ready(函数(){
变量$body=$('body');
$body.html(“”);//之前的h1标记
var指数=streams.home.length-1;
而(索引>=0){
var tweet=streams.home[index];
var$tweet=$('');
$tweet.text(“@”+tweet.user+”:“+tweet.message);
$tweet.appendTo($body);
指数-=1;
}
});
jQuery的函数将主体的html替换为标题标记。你想要的是或者,在已有的基础上增加
例如:
更多推特!
$(文档).ready(函数(){
变量$body=$('body');
$body.prepend(“”);//之前的h1标记
var指数=streams.home.length-1;
而(索引>=0){
var tweet=streams.home[index];
var$tweet=$('');
$tweet.text(“@”+tweet.user+”:“+tweet.message);
$tweet.appendTo($body);
指数-=1;
}
});
$body.html(“…”)代码>删除正文中以前设置的任何内容,请使用append()
或prepend()
instead@chewchew如果我们解决了您的问题,请考虑将其中一个答案标记为“接受”,使用灰色复选标记。谢谢