ontouchstart和onquo​​uchend在jquery?

Olo*_*koo 8 html css jquery html5 touch

我目前正在使用以下内容为我想要更改触摸类的每个元素:

ontouchstart="$(this).addClass('select');" ontouchend="$(this).removeClass('select');"
Run Code Online (Sandbox Code Playgroud)

我想知道是否有这样的事情?:

$("#element").touchstart(function(){
    $(this).addClass('select');
},
function(){
   $(this).removeClass('select');
});
Run Code Online (Sandbox Code Playgroud)

我将能够列出我想拥有此属性的所有元素.我尝试了很多东西,无法让它发挥作用.

Olo*_*koo 15

我最终只使用了这个:

$('#nav li').bind('touchstart', function(){
    $(this).addClass('select');
}).bind('touchend', function(){
    $(this).removeClass('select');
});
Run Code Online (Sandbox Code Playgroud)


Rei*_*.85 12

没有JQUERY:

element.addEventListener('touchstart',function(e) {
 e.currentTarget.className = "select";
});
Run Code Online (Sandbox Code Playgroud)

随着JQUERY

$('#nav ul li a').on('touchstart', function(){
    $(this).addClass('select');
});
Run Code Online (Sandbox Code Playgroud)

实际上,on()获得比bind()更好的性能,检查文档