我很抱歉,因爲我知道這是一個重複的問題,但我已經搜索了所有我可以並嘗試了我發現的一切,似乎沒有任何工作。我想要做的是在我的html文檔中動態分配一個div,然後用谷歌可視化圖表填充它。Javascript動態變化div尺寸
我有這一切工作正常,除了一件事。我無法讓div的增加的該死的尺寸!這裏是我的代碼:
var thisDashboard = document.createElement(chartDivID);
thisDashboard.setAttribute("style", "width: 1000 px; height 425 px;");
thisDashboard.setAttribute("id", chartDivID);
//thisDashboard.style.height = 425 + "px";
//thisDashboard.style.width = "1000px";
document.getElementById("chartArea").appendChild(thisDashboard);
var thisChart = document.createElement(chartDivID + "_chart");
thisChart.setAttribute("style", "height: 300 px; width: 100%");
thisChart.setAttribute("id", chartDivID + "_chart");
//thisChart.style.height = 300 + "px";
//thisChart.style.width = 100 + "%";
thisDashboard.appendChild(thisChart);
正如你可以看到我已經嘗試使用.setAttribute和.style.width和.style.height之間的每一個組合我能想到的。由於某種原因,它只是不會工作。這是圖表區域div:
<div id="chartArea" style="width: 100%"></div>
我能夠使被隱藏的元素出現在新創建的div中,但寬度不會改變!我在這裏錯過了一件非常明顯的事情嗎?
你可以使用[JS小提琴](http://jsfiddle.net/)或類似的演示來演示這個嗎?因爲這看起來應該起作用。 –