我很抱歉,因为我知道这是一个重复的问题,但我已经搜索了所有我可以并尝试了我发现的一切,似乎没有任何工作。我想要做的是在我的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/)或类似的演示来演示这个吗?因为这看起来应该起作用。 –