简体   繁体   English

禁用网页上的触摸事件

[英]Disable Touch events on webpage

I have a webpage with form and I am trying to disable the touch events in that webpage I am trying to not focus on the input field with touch.我有一个带有表单的网页,我试图禁用该网页中的触摸事件我试图不关注带有触摸的输入字段。

For example, page load focus will go to the input field and the user will enter anything in the input field through a keypad eg 12345.例如,页面加载焦点将 go 到输入字段,用户将通过键盘在输入字段中输入任何内容,例如 12345。

Now I want to restrict the user that user can't select or move back to any letter and delete it using touch screen using keypad he can现在我想限制用户不能使用 select 或移回任何字母并使用触摸屏使用键盘删除它

If you mean touch actions, you can disable them by inserting this string in your css in the desired container / body如果您的意思是触摸操作,您可以通过将此字符串插入所需容器/正文中的 css 来禁用它们

body {
    touch-action: none;
}

Read more about touch-action : https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action阅读有关touch-action更多信息: https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action

As Matteo said you could use touch events in the body tag.正如Matteo所说,您可以在 body 标签中使用触摸事件。 However, if you need to do it with js you can add an event listener that will react to a bunch of actions like touchstart, touchmove, touchend.然而,如果你需要用 js 来做,你可以添加一个事件监听器,它会对一系列动作做出反应,比如 touchstart、touchmove、touchend。

Here is the code snippet for that:下面是代码片段:

document.querySelector('.your-element').addEventListener('touchend', function (event) {
        e.preventDefault();
    });

MDN docs: Touch events MDN 文档: 触摸事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM