gpt4 book ai didi

javascript - Jquery load() 加载的内容超出了我的预期

转载 作者:行者123 更新时间:2023-11-28 14:04:08 25 4
gpt4 key购买 nike

我正在尝试仅加载 <div> 的内容进入另一个<div>在同一页面上使用 jquery 函数。但是当该函数触发时,它会加载整个 <HTML>文件写入指定<div> 。知道为什么要这样做吗?我的代码如下:

Jquery:

function button1() {
$('#sidebar-content').fadeOut(function() {
$(this).load('#button1').fadeIn();
});
}
function button2() {
$('#sidebar-content').fadeOut(function() {
$(this).load('#button2').fadeIn();
});
}

HTML:

<div id="content-holder"> 
<div id="main-content" class="float-holder">
<div id="inner">
<h1>BRAND TRUTH</h1>
<div id="flashcontent">
<div id="button1">
<div id="content">
<h1>Brand Truth</h1>
<p>What this basically means is our way of working, the process involved by both ourselves and our client.</p>

<p>When the truth wheel process is followed, the end result is so much stronger.</p>
</div>
</div>
<div id="button2">
<div id="content">
<h1>Button 2 Content</h1>
<p>Some other content</p>

<p>Some other content x2</p>
</div>
</div>
</div>
<script type="text/javascript">
// <![CDATA[

var so = new SWFObject("working.swf", "working", "400", "400", "9", "#FFFFFF");
so.write("flashcontent");

// ]]>
</script>

</div>
<div id="sidebar">
<div id="sidebar-content">
Replace Content Here!
</div>
</div>
</div><!-- end #main-content -->
</div><!-- end #content-holder -->

最佳答案

.load() 是一个通过AJAX加载远程网页的功能,你想要的是使用 .html() ,像这样:

function button1() {
$('#sidebar-content').fadeOut(function() {
$(this).html($('#button1').html()).fadeIn();
});
}
function button2() {
$('#sidebar-content').fadeOut(function() {
$(this).html($('#button2').html()).fadeIn();
});
}

.html()不带参数获取里面的 html,所以我们从按钮 <div> 获取它,然后.html(string)设置里面的 html,我们正在处理结果。

关于javascript - Jquery load() 加载的内容超出了我的预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2887661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com