gpt4 book ai didi

javascript - DIV属于元素,你怎么知道的?

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

我有两个 div,其中包含一些元素(图像、文本等),我需要知道哪个 div 包含被单击的元素。例如:

  • 如果我点击 div 1 中的任何元素,则重定向到“pagina1.php”
  • 如果我点击 div 2 中的任何元素,则重定向到“pagina2.php”

我如何在 jquery 中执行此操作?

最佳答案

只需将点击处理程序绑定(bind)到 DIV(您的内容包装器):

$( '#div1, #div2' ).click( function ( e ) {

this // references the DIV inside which the click occured
e.target // references the element that was clicked

});

关于javascript - DIV属于元素,你怎么知道的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897141/

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