我有一個棘手的問題要解決,到目前爲止我還沒有找到一個好的解決方案。對不起,我是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