欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery替換已存在于element上的event的方法

 更新時(shí)間:2010年03月09日 21:08:16   作者:  
如何替換獲去除那些已存在于某個(gè)element上的事件呢? 需要的朋友可以參考下面的文章。
看下面code:
復(fù)制代碼 代碼如下:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>TestPage</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#btn1").unbind('click').removeAttr('onclick').click(function() {
alert('The method has invoked by Jquery.');
});
});
function foo()
{
alert('The method has invoked.');
}
</script>
</head>
<body>
<input type="button" value="ClickMe" id="btn1" onclick="foo()" />
</body>
</html>

用的就是unbind,然后再removeAttr,最后再加上你的方法。來看下它們API document:
unbind([type], [fn])
概述
bind()的反向操作,從每一個(gè)匹配的元素中刪除綁定的事件。
如果沒有參數(shù),則刪除所有綁定的事件。
你可以將你用bind()注冊(cè)的自定義事件取消綁定。
如果提供了事件類型作為參數(shù),則只刪除該類型的綁定事件。
如果把在綁定時(shí)傳遞的處理函數(shù)作為第二個(gè)參數(shù),則只有這個(gè)特定的事件處理函數(shù)會(huì)被刪除。
參數(shù)
type (可選)String
事件類型
fn (可選)Function
要從每個(gè)匹配元素的事件中反綁定的事件處理函數(shù)
removeAttr(name)
概述
從每一個(gè)匹配的元素中刪除一個(gè)屬性
參數(shù)
nameString
要?jiǎng)h除的屬性名
簡(jiǎn)單的就是:
復(fù)制代碼 代碼如下:

$("#someelement").unbind('eventname').removeAttr('event').click(function() {
//your new method.
});

希望對(duì)您有幫助。

相關(guān)文章

最新評(píng)論