Re: [問題] getElementById 有辦法動態修改 id 嗎?
※ 引述《sweetwords (米虫三號)》之銘言:
: 最近想寫一個動態視窗,可以針對所點取的選項跳出說明視窗
: 只不過不知道為啥,如果只是單一跳脫視窗可以,但是如果很多利用變數去控制
: 就沒辦法跳出來,不知道是哪有問題
下次要記得附上錯誤訊息...不是每個人都是肉眼compiler.
: 附上程式碼
: 我 showPopup 傳入三個變數 w, h, id <--- 這是要顯示哪一個 div 的屬性
: function showPopup(w,h,id){
: var popUp = document.getElementById("id");
^^^^ 這id真的是 "id" 嗎?
感覺你這裡應該是要帶傳入的 id 喔
把雙引號拿掉寫變數名稱 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 />
^^^^^^^^^^^^
看起來是要給字串,那應該要加上''變成'popupcontent'
下面這行也一樣
: <a href="#" onclick="showPopup(300,200,popupcontent2);" >最新消息2</a><br />
: 煩請各位大大解讀 <(_ _)>
--
What do you want to have ? / What do you have?
從書本中,你可以發現我的各種興趣。
從CD中,你可以瞭解我所喜歡的偶像明星。
或許從文字你很難以瞭解一個人,但從物品可以。
My PPolis , My past. http://ppolis.tw/user/Tony
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 74.207.224.18
※ 編輯: TonyQ 來自: 74.207.224.18 (03/08 12:53)
※ 編輯: TonyQ 來自: 74.207.224.18 (03/08 13:26)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章