I want to set the w开发者_Python百科idth of an applet with the width of the div that he is in. How can I do that?
Assuming applet has an id of "myApplet":
Note: This will only work if the div
element's width is set directly on the element (not using a stylesheet)
var myApplet = document.getElementById("myApplet");
myApplet.width = myApplet.parentNode.style.width;
<applet id="foo" ...></applet>
...
var app = document.getElementById('foo');
app.width = app.parentNode.offsetWidth;
精彩评论