我有一个棘手的问题要解决,到目前为止我还没有找到一个好的解决方案。对不起,我是JS的新手。基于下拉实例化新的javascript
我有一个下拉选择一个持续时间1小时,2小时等我试图切换什么脚本,我将基于下拉列表运行。我遇到了一些问题。
我简单的html看起来像这样
<div id="content">
<h2>Some Stats</h2>
<section><div id="legend"></div></section>
<div id="chart_container">
<div id="graph"></div>
</div>
</div>
<!-- My graph generates above "legend", "chart_container", and "graph". time_duration is a variable that is generated by the dropdown-->
<script>
$(document).ready(function(){
//dropdown
$("#DateFilter").change(function(){
var current = $(this).find("option:selected").attr("id");
graph = new graph("path_to_url" + current);
graph.render();
});
});
</script>
当我尝试更改持续时间,生成基于新的时间内完成新的图形,但被覆盖在当前的顶部。
这是因为“legend”,“chart_container”和“图形”divs仍旧是旧的。此外,图形不断运行(使用setInterval)。
我可以用新的替换整个当前的图表,而不是诉诸使用JQuery的每个人使用多个div(和使用隐藏,显示)?
我想你可以用'$( '#图')清除现有的'div' HTML( “”)' - 是:
阅读更多。那你的意思是? – ochi 2014-12-03 23:56:09
正是我要发布的内容:ie。清除你正在绘制的当前元素中的html – Will 2014-12-03 23:56:50
@ochi我正要说同样的事情。根据当前发布的代码提供更好的指导很困难。 – wahwahwah 2014-12-03 23:57:16