gpt4 book ai didi

javascript - jquery中如何获取基本选择器

转载 作者:行者123 更新时间:2023-12-02 22:17:15 27 4
gpt4 key购买 nike

我有一个这样的脚本:

var target = $('#box1, #box2, #box3, #boxn').find('.content p');
target.hover(function() {
alert([the base element]);
})

我需要获取基本元素 #box1#box2#box3 等,其中包含鼠标悬停在其自身上的元素.

有办法做到这一点吗?

最佳答案

jQuery 事件处理程序有一个 general form可以处理你所问的问题:

// `.hover()` is a helper for handling both `mouseenter` and `mouseleave`
$('#box1, #box2, #box3, #boxn').on('mouseenter mouseleave', '.content p', function(event) {
// element that is currently the focus of the bubbled event;
// usually the same as `this`, the element on which the event was triggered
console.log(event.currentTarget);
// element to which this handler is bound
console.log(event.delegateTarget);
});

如果这样设置,.delegateTarget 将是您想要的父元素。

关于javascript - jquery中如何获取基本选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59346774/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com