1

我的目标是根据观众屏幕的比例改变对象高度

我有javascript代码:

var rat = ((screen.availWidth / screen.availHeight)*100);
document.getElementById('myP').innerHTML=rat;

并希望将其应用于 HTML 代码:

object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" width="100% height="id='myP'" id="myFlashContent" align="middle" allowFullScreen = "true"

但我不确定如何将变量写入代码。

4

2 回答 2

2

尝试 :

var rat = ((screen.availWidth / screen.availHeight)*100);
    d = document.getElementById('myP');
    d.style.height=rat+"%";
于 2012-07-18T20:03:04.280 回答
1

The way you are doing it is incorrect.

1. Assign an id to your object.

 <object id="obj" classid="..." ....>

2. Change your javascript to

var rat = ((screen.availWidth / screen.availHeight)*100);
document.getElementById('obj').setAttribute("height", rat);
于 2012-07-18T19:59:10.530 回答