gpt4 book ai didi

带有 $(this) 的 jQuery 多重选择器

转载 作者:行者123 更新时间:2023-12-03 22:20:08 25 4
gpt4 key购买 nike

有什么办法可以做到这一点:

$(this, '#foo')

我也想选择“this”元素和#bar。要选择两个 ID,就像 '#foo, #bar' 一样简单。 ,但是当我希望这两个之一成为“这个”时,我无法让它工作。

最佳答案

你的方法有问题

$(this, '#foo')

上面的行将在 id 设置为 foo 的元素内搜索 this,这不是您想要的。

<小时/>

解决方案

您可以使用add()来实现:

var $el = $(this).add('#foo')

现在 $el 将包含 $(this)$("#foo"),您可以对其执行操作。

<小时/>

有关所用方法的更多信息

添加(“选择器”)

关于带有 $(this) 的 jQuery 多重选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17506208/

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