作者LaPass (LaPass)
看板Ajax
標題[問題] 設定ondblclick時,有辦法指定值嗎?
時間Sat Jan 7 19:19:22 2012
目前做個按鈕,可以點他的時候,在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
1F:→ grence:newItem.ondblclick = function, not string. 01/07 19:31
2F:推 mrbigmouth:newItem.ondblclick=function(){removeItem(id);}; 01/07 21:29
3F:→ mrbigmouth:newItem.自己加 01/07 21:29
4F:→ LaPass:試出來了,感謝 ^^" 01/07 22:26
5F:→ LaPass:ie9 點下去會沒反應 orz.... 到底是怎麼回事 01/09 16:59
6F:→ LaPass:筆記: ie的option沒有ondblclick事件 01/13 19:36