简体   繁体   English

使用JQUERY重新加载div而不重新加载页面

[英]Reloading a div without reloading a page using JQUERY

I am working with amCharts and want to put a simple button in the my header that gives the option to refresh the chart chart div when needed. 我正在使用amCharts,并希望在我的标题中放置一个简单的按钮,该按钮提供了在需要时刷新统计图div的选项。

I have looked all over the internet for a solution and all the code I have found is similar to what I am using, it does not want want to reload the div. 我在互联网上寻找解决方案,发现的所有代码都与我使用的代码相似,它不想重新加载div。 Being new at JQUERY I am not sure what I doing wrong. 作为JQUERY的新手,我不确定自己做错了什么。

your assistance is greatly appreciated. 非常感谢您的协助。

I have attached the JQUERY and HTML code Below: 我已在下面附加了JQUERY和HTML代码:

<div id="chartwrapper">
    <!-- Unit Price Dollar -->
    <div id="unit-price" style="text-align: center; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 14px; color: #666; clear: both; margin-bottom: 20px;">VPM Global Select Opportunities Fund - Dollar Unit Price
        <br> Weekly: 2012/02/03 to 2014/10/24

    </div>
    <div id="chartdiv1" style="width:100%; height:600px;"></div>

    <!-- Unit Price Dollar Target Return -->
    <div id="unit-price-value" style="text-align: center; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 14px; color: #666; clear: both; margin-bottom: 20px;">Value of $1000 Invested at inception relative to Target Return
        <br> Weekly: 2012/02/03 to 2014/10/24
    </div>
    <div id="chartdiv2" style="width:100%; height:600px;"></div>

    <!-- Unit Price Rand Versus Inflation -->
    <div id="unit-price-rand" style="text-align: center; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 14px; color: #666; clear: both; margin-bottom: 20px;">Value of R1000 Invested at inception relative to Inflation Benchmarks
        <br> Weekly: 2012/02/03 to 2014/10/24
    </div>
    <div id="chartdiv3" style="width:100%; height:600px;"></div>

    <div style="text-align: center; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 12px; color: #666; clear: both;">
        <br>* VPM GSO - VPM Global Select Opportunities Fund
    </div>
    <br>
</div>
<!-- END CHART WRAPPER -->

jQuery: jQuery的:

$(document).ready(function() {
    $("#resetZoom1").bind("click", function() {
        var url = 'index.html';
        $("#chartwrapper").load( url + "div#chartdiv1")
    });
});

From the documentation : 文档中

The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. 与$ .get()不同,.load()方法允许我们指定要插入的远程文档的一部分。 This is achieved with a special syntax for the url parameter. 这可以通过使用url参数的特殊语法来实现。 If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded. 如果字符串中包含一个或多个空格字符, 则假定字符串中第一个空格之后的部分是jQuery选择器 ,它确定要加载的内容。

So, you must use a space: 因此,您必须使用空格:

$("#chartwrapper").load(url + " div#chartdiv1");
                  //           ^
                  // a space --'

Or, this is better (without div ): 或者,这更好(不使用div ):

$("#chartwrapper").load(url + " #chartdiv1");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM