作者sweetwords (米虫三号)
看板Ajax
标题[问题] getElementById 有办法动态修改 id 吗?
时间Mon Mar 8 12:43:36 2010
最近想写一个动态视窗,可以针对所点取的选项跳出说明视窗
只不过不知道为啥,如果只是单一跳脱视窗可以,但是如果很多利用变数去控制
就没办法跳出来,不知道是哪有问题
附上程式码
我 showPopup 传入三个变数 w, h, id <--- 这是要显示哪一个 div 的属性
function showPopup(w,h,id){
var popUp = document.getElementById("id");
popUp.style.top = "200px";
popUp.style.left = "200px";
popUp.style.width = w + "px";
popUp.style.height = h + "px";
if (baseText == null) baseText = popUp.innerHTML;
popUp.innerHTML = baseText + "<div id=\"statusbar\"><button
onclick=\"hidePopup(id);\">Close window</div>";
var sbar = document.getElementById("statusbar");
sbar.style.marginTop = (parseInt(h)-40) + "px"; popUp.style.visibility =
"visible";
}
<!-- div 我都用 hidden 让其不显示出来,要用再打开 -->
<div id="popupcontent">
hello world
</div>
<div id="popupcontent2">
hello world2
</div>
<!-- link -->
<a href="#" onclick="showPopup(300,200,popupcontent);" >最新消息</a><br />
<a href="#" onclick="showPopup(300,200,popupcontent2);" >最新消息2</a><br />
烦请各位大大解读 <(_ _)>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.15.171.146
1F:→ emn178:var popUp = document.getElementById(id); 03/08 12:53
2F:→ sweetwords:一样不行 无动於衷 XD 03/08 12:59
3F:→ emn178:要改的地方太多了 那就改天吧 03/08 17:53
4F:推 eight0:showPopup(300,200,'popupcontent'); 03/14 18:46