jQuery event.delegateTarget 属性

jQuery 教程 · 2019-03-10 22:27:44

实例

改变 <div> 元素的背景颜色(<button> 元素的祖先):

$("div").on("click","button",function(event){
    $(event.delegateTarget).css("background-color", "pink");
});

定义和用法

event.delegateTarget 属性返回当前调用的 jQuery 事件处理程序所添加的元素。

该属性对于由 on() 方法添加的委托事件非常有用,事件处理程序是在元素的祖先被处理时添加的。

提示:如果事件直接绑定到元素且没有委托发生,则 event.delegateTarget 等同于 event.currentTarget(参见下面的实例)。

语法


event.delegateTarget

参数 描述
event 必需。event 参数来自事件绑定函数。

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

The Little Typer

The Little Typer

Daniel P. Friedman、David Thrane Christiansen、Duane Bibby、Robert Harper、Conor Mcbride / MIT Press / 2018-10-16 / GBP 30.00

An introduction to dependent types, demonstrating the most beautiful aspects, one step at a time. A program's type describes its behavior. Dependent types are a first-class part of a language, and are......一起来看看 《The Little Typer》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具