Zi 字媒體
2017-07-25T20:27:27+00:00
.on()這個方法是將某個selector元素一次全部載入相同的event,.live()、.delegate()和.bind()都是.on()的前身(至於有何差異這邊不多做解釋)
.on()用法
//將selector都載入click事件
$("table td").on("click",function(e){
alert( $(this).html() );
});
//將selector底下的td元素都載入click事件
$("table").on("click", "td",function(e){
alert( $(this).html() );
});
//傳值給event
$("table").on("click", {name:"KY"},function(e){
alert( e.data.name );
});
.off()的功能則是跟.on()相反
.off()用法
//停用selector所有事件
$("table td").off();
//停用selector所有click事件
$("table td").off("click");
/*
關閉selector底下的td元素的click事件
只派的方式需相同才對應的到
例如
$("table td").on("click", test);
要停用事件就必須使用
$("table td").off("click", test);
*/
$("table").on("click", "td", test);
$("table").off("click", "td", test);
function test() {
alert( $(this).html() );
}
Categories: jQuery
分類
Android
AngularJS
API Blueprint
Chrome
Database
MySQL
DataStructure
Docker
Editor
Vim
Firefox
Git
GitLab
Google API
Hadoop
HTTP
Language
Go
Java
JavaScript
jQuery
jQueryChart
Node.js
Vue
Vue-CLI
PHP
Laravel
Lumen
ZendFramework
Python
Mac
Network
Cisco
DLink
Juniper
Oauth
Server
Apache
Share
Unix
FreeBSD
Linux
WebDesign
Bootstrap
CSS
HTML
Wordpress
Search
搜尋關鍵字:
寫了
5860316篇文章,獲得
23313次喜歡