条件JavaScript代码不执行 [英] conditional javascript code not executing

查看:129
本文介绍了条件JavaScript代码不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  $('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){


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 :)

解决方案

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

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

这篇关于条件JavaScript代码不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆