[問題] getElementById 有辦法動態修改 id 嗎?
最近想寫一個動態視窗,可以針對所點取的選項跳出說明視窗
只不過不知道為啥,如果只是單一跳脫視窗可以,但是如果很多利用變數去控制
就沒辦法跳出來,不知道是哪有問題
附上程式碼
我 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
→
03/08 12:53, , 1F
03/08 12:53, 1F
→
03/08 12:59, , 2F
03/08 12:59, 2F
→
03/08 17:53, , 3F
03/08 17:53, 3F
推
03/14 18:46, , 4F
03/14 18:46, 4F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章