Re: [問題] getElementById 有辦法動態修改 id 嗎?

看板Ajax作者 (沉默是金。)時間15年前 (2010/03/08 12:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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)
文章代碼(AID): #1Bb89mGT (Ajax)
文章代碼(AID): #1Bb89mGT (Ajax)