conditional javascript code not executing

吃可爱长大的小学妹 提交于 2020-01-11 13:22:51

问题


Does anyone know why this code might not work? touchmove and touchend do not execute only touchstart because that's a seperate event and 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);}
    });

Thanks a lot for any attempt :)


回答1:


The event names in the first argument to ".live()" need to be separated by spaces, not commas.

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



回答2:


I think this would work

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



回答3:


First off, your event variable should be the parameter e rather than event.

Second, when testing for equality, you need two equals signs: ==. One equals sign is the assignment operator.




回答4:


What does the console say when you open your site / trying to run the method? :)

//Gerner



来源:https://stackoverflow.com/questions/5997966/conditional-javascript-code-not-executing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!