Mobile Safari - event.target in touch event

后端 未结 1 809
暗喜
暗喜 2021-01-27 04:05

I would like to have the target when a touch something on the screen of my iPad. But unfortunately it always returns the currentTarget, never the target.

<         


        
1条回答
  •  清酒与你
    2021-01-27 04:32

    You might try the "event.touches" array, which will have one entry for each finger currently down, with the "target" value referencing the DOM element touched.

    function onDocumentTouchStart(event) {
        if (event.touches[0] && event.touches[0].target.tagName.toLowerCase() == "div") {
            // do someting
        }
    }
    

    However, I should note that I was unable to duplicate the original issue; when I tried it, event.target referred to the touched div as intended. You might also check your CSS and/or JS plugins that might be interfering with event bubbling.

    0 讨论(0)
提交回复
热议问题