[問題] 設定ondblclick時,有辦法指定值嗎?

看板Ajax作者 (LaPass)時間14年前 (2012/01/07 19:19), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/1
目前做個按鈕,可以點他的時候,在select 裡面加個option 並在點option兩下時,刪除該option 現在我打算設置option的ondblclick 在裡面加入刪除該物件的事件 可是不知道該怎麼設置 function addItem() { var newItem = document.createElement("option"); var inputText = document.getElementById("textbox").value; if(inputText == "" || inputText == "請輸入內容") { alert("請輸入內容"); return; } newItem.text = inputText; newItem.id = "oId" + oId++; //newItem.ondblclick = "removeItem("+newItem.id+")"; //不能這樣用 itemBox.appendChild(newItem); } function removeItem(rmId) { for(var i =0; i<itemBox.length; i++) { if(itemBox.options[i].id == rmId) { itemBox.options.remove(i); break; } } } 我請問javascript是如何處理這種狀況的? 我不知道這個問題該用什麼關鍵字去google...... 一直找不到想要的答案 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.41.109.80

01/07 19:31, , 1F
newItem.ondblclick = function, not string.
01/07 19:31, 1F

01/07 21:29, , 2F
newItem.ondblclick=function(){removeItem(id);};
01/07 21:29, 2F

01/07 21:29, , 3F
newItem.自己加
01/07 21:29, 3F

01/07 22:26, , 4F
試出來了,感謝 ^^"
01/07 22:26, 4F

01/09 16:59, , 5F
ie9 點下去會沒反應 orz.... 到底是怎麼回事
01/09 16:59, 5F

01/13 19:36, , 6F
筆記: ie的option沒有ondblclick事件
01/13 19:36, 6F
文章代碼(AID): #1F22ezCj (Ajax)