2010-08-05 21 views
3
<input name="mybutton" type="button" class="agh" id="id_button" value="Dim" onClick="resetDims();"> 

在上面的輸入標籤中,我必須刪除整個「Onclick = myfunction();」其爲輸入標籤功能,寫我的功能,此按鈕,當我們的「點擊」如何刪除按鈕的現有JavaScript功能

$("#mybutton").onclick(function(){ 
    //$("#mybutton").removeattr("onClick",""); 
}) 
+0

是的,你有什麼問題嗎? – adamse 2010-08-05 14:43:22

+0

'mybutton'是元素的名稱屬性,您需要查詢'#id_button'。 – jAndy 2010-08-05 14:48:48

回答

3

如果您需要刪除 「點播」 的onclick屬性使用

$('#id_button').removeAttr('onclick').click(function(){ 
}); 

有一個第二次看選擇。您需要查詢ID,您的代碼段 trys選擇mybutton作爲ID,這實際上是元素的名稱。

+0

謝謝安迪它解決了我 – Someone 2010-08-05 14:54:53

0

可以使用jQuery unbind function如果你想刪除的單擊事件。

$('#mybutton').unbind('click'); 
+0

這將不會與'onclick'內聯事件處理程序一起工作 – jAndy 2010-08-05 14:44:25

+0

是的,我會採用jAndy解釋的方法,因爲unbind在我的應用程序中不起作用。 – 2010-08-05 15:06:17

+0

@jAndy - 他沒有添加HTML代碼來清楚說明這是我在回答時的內聯事件。 – 2010-08-05 15:14:28

1

使用unbind刪除事件偵聽器。

$("#mybutton").click(function(){ 
    $(this).unbind("click"); 
}) 

(也$().click,不onclick

2

您不能使用unbind刪除inline model onclick處理程序。 unbind只能用於jQuery綁定的事件處理程序。這是可以做到這樣的:

document.getElementById("id_button").onclick = null; 

// you can still get the element using the jQuery shorthand though 
// the point is to get at the DOM element's onclick property 
$("#id_button")[0].onclick = null; 

演示:http://jsfiddle.net/ax52z/