条件javascript代码不执行

有谁知道为什么这段代码可能不起作用? touchmove和touchend不执行touchstart,因为这是一个单独的事件和function:)

$('input').live("touchstart", function (e) {$(this).addClass('click')}); $('input').live("touchmove,touchend", function (e) { if (e.type == 'touchmove'){ $('.temp').removeClass('temp'); $('.click').removeClass('click'); } else{var inputvalue = $(this).val() $('input[value="' + inputvalue + '"] + label').css({ '-webkit-transition': 'opacity 0.3s linear', 'opacity': '0' }); setTimeout(function () { $('input[value="' + inputvalue + '"] + label').css({'-webkit-transition': '0','opacity': '1'}); $('.temp').removeClass('temp'); $('.click').removeClass('click'); }, 300);} }); 

非常感谢任何尝试:)

“.live()”的第一个参数中的事件名称需要用空格分隔,而不是用逗号分隔。

 $('input').live("touchmove touchend", function (e) { 

我认为这会奏效

 $('x').live("ontouchmove, ontouchend", function (e) { //do stuff if (e.type == 'ontouchmove'){ //do stuff } else{ //do stuff } }); 

首先,您的事件变量应该是参数e而不是event

其次,在测试相等性时,需要两个等号: == 。 一个等号是赋值运算符。

当您打开站点/尝试运行该方法时,控制台会说什么? 🙂

// Gerner