gpt4 book ai didi

javascript - jQuery : Attaching mouseup event to all textnodes of a container

转载 作者:行者123 更新时间:2023-11-30 07:48:09 26 4
gpt4 key购买 nike

我想在容器的所有节点上附加一个“mouseup”事件,包括使用 jQuery 的文本节点。我该怎么做?

更新:

如果我有这样的 HTML 片段:

<p>Some text node <strong>strong text</strong> another text node.</p>

目前,$("p *") 会将事件应用于 <p><strong>但不是 <p> 中的 2 个文本节点分别地。修改源代码以添加类不是一种选择。

最佳答案

bobince 是正确的,您不能在文本节点上设置事件处理程序。听起来你想要类似的东西

<p><span>Some text node</span> <strong>strong text</strong><span> another text node.</span></p>

并且事件将附加到 span 标签。但是,如果您不能更改源,那将不起作用。

关于javascript - jQuery : Attaching mouseup event to all textnodes of a container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1880881/

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