简体   繁体   English

touchend电话相当于js中的onmouseup吗?

[英]Is touchend the phone equivalent of onmouseup in js?

I have my web app working fine with computers, but can't seem to get it to work on mobile phones mainly because the onmouseup isn't being fired off. 我的网络应用程序可以在计算机上正常运行,但似乎无法使其在手机上正常运行,主要是因为未激活onmouseup。 So I added the touchend event thinking it would be the same, but it didn't help. 因此,我添加了touchend事件,认为它是相同的,但没有帮助。 How do I get the same behavior of onmouseup on the phone? 如何在电话上获得onmouseup的相同行为?

Basically, I have a range slider and I want the release slider part of it to work on phones 基本上,我有一个范围滑块,我希望它的释放滑块部分可以在手机上使用

  <input id="slider" class="slider" type="range" min="0" max="100" value=50 onmouseup="handleSubmit()" touchend="handleSubmit()"/>

I've tried it on mobile safari and chrome... neither work 我已经在Safari和chrome浏览器上尝试过...都行不通

You don't need to rely on mouseup nor touchend. 您无需依靠mouseup或touchend。 The input element offers another event which comes in handy: onchange . 输入元素提供了另一个方便的事件: onchange

This input fires as soon the input's value changed - because the user released the slider. 输入值更改后立即触发该输入-因为用户释放了滑块。

Here's an example: 这是一个例子:

 function handleSubmit(e) { console.log(e.value) } 
 <input id="slider" class="slider" type="range" min="0" max="100" value=50 onchange="handleSubmit(this)" /> 

I'm stupid... it's supposed to be ontouchend 我很蠢...应该是在接触

<input id="slider" class="slider" type="range" min="0" max="100" value=50 onmouseup="handleSubmit()" touchend="handleSubmit()"/>

still new to js haha 对JS还是个新手哈哈

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

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