简体   繁体   English

jQuery load()加载超过我想要的

[英]Jquery load() loading more than I want

I am trying to load just the contents of a <div> into another <div> on the same page using a jquery function. 我正在尝试使用jquery函数将<div>的内容仅加载到同一页面上的另一个<div> But when the function triggers, it loads the entire <HTML> document into the specified <div> . 但是当函数触发时,它将整个<HTML>文档加载到指定的<div> Any idea why it would be doing this? 知道为什么会这样做吗? My code is as follows: 我的代码如下:

Jquery: jQuery的:

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

HTML: 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() is a function to load a remote webpage via AJAX, what you want is to use .html() , like this: .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() without a parameter gets the html inside, so we're getting it from the button <div> , then .html(string) sets the html inside, which we're doing with the result. 没有参数的.html()获取html的内部内容,因此我们从按钮<div>获取它,然后.html(string)设置html的内部内容,并对结果进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jquery每页加载只能运行一次 - 希望它不必重新加载页面就可以多次运行 - Jquery only works once per page load - want it work more than once without having to reload page jQuery.load function 问题多次加载未指定的元素 - jQuery.load function issue loading unspecified elements more than once jQuery仅在调整大小时加载,我希望它在调整大小和页面加载时均加载 - jQuery is only loading on resize and I want it to load on both resize and page load 正则表达式比我想要的更多 - Regex replacing more than I want jQuery滚动加载更多数据而不加载更多数据 - jQuery load more data on scroll not loading more data 只加载一次 Json 文件,然后我想从加载的文件评估器中获取而不是再次加载 - Load Json file for one time only and After wards I want to fetch from loaded file rater than loading again jquery 选项卡 - 想要在同一页面上多次使用 - jquery tabs - want to use more than once on same page 警告:试图加载角度不止一次...因为jQuery ...为什么? - WARNING: Tried to load angular more than once…because of jQuery…why? jQuery.load() 方法为每个元素多次加载内容 - jQuery .load() method loads content more than once for each element 正则表达式的输入量也超出了我的预期 - Regular Expression puts in more than I want it too
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM