[問題] 在ie中動態插入/刪除 object tag 的 size
在ie裏面我透過jquery去動態新增刪除object的tag時碰到奇怪的狀況
我新增一個object node的方式是用jquery的html()這隻function將object的內容
掛到特定的node下
然後要刪除的時候是用remove()的方式
但是當我用html()加入object tag之後
它的width跟height無論怎麼去設定
透過ie8的開發人員工具去觀看插入後的結果得到的都是0
也就是即使有插入了也無法顯示出來
但同樣的狀況在其它的browser中不會發生
後來我用css的方式加上給object tag一個class 的attr
.obj{width:100px !important;} <-- 類似這樣的方式可以強制去讓object tag
在插入之後的大小設定成功
但因為是用了 !important 參數 所以如果要動態去改size就變得有問題
想請教問題是出在什麼地方...為什麼ie8在預設的width跟height是0呢...
=
附一下簡短的html code做為參考 @@~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>plugin test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
.obj {
width:200px !important; //如果沒加上!important
height:200px !important; //object tag就不會顯示出來
}
</style>
<script type="text/javascript">
$("#obj-area-1").html("");
$("#obj-area-2").html("");
function area1()
{
var obj = null;
$("#obj").remove();
obj = "<OBJECT classid='' width='200' height='200' id='o1' class='o1'
events='True'>";
obj += "</OBJECT>";
$("#obj-area-1").html(obj);
}
function area2()
{
var obj = null;
$("#obj").remove();
obj = "<OBJECT classid='' width='200' height='200' id='o1' class='o1'
events='True'>";
obj += "</OBJECT>";
$("#plugin-area-2").html(obj);
}
</script>
</head>
<body>
<div>
<div>obj-area-1</div>
<div id="obj-area-1">
</div>
</div>
<div>
<div>obj-area-2</div>
<div id="obj-area-2">
</div>
</div>
<input type="button" value="area 1" onclick="area1();">
<input type="button" value="area 2" onclick="area2();">
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.250.145.25
→
09/16 18:53, , 1F
09/16 18:53, 1F
→
09/20 17:55, , 2F
09/20 17:55, 2F
→
09/20 17:55, , 3F
09/20 17:55, 3F
→
09/20 23:29, , 4F
09/20 23:29, 4F
→
09/20 23:29, , 5F
09/20 23:29, 5F
→
09/20 23:29, , 6F
09/20 23:29, 6F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章