[英]conditional javascript code not executing
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 :)
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);}
});
Thanks a lot for any attempt :) 非常感谢您的尝试:)
“ .live()”的第一个参数中的事件名称需要用空格而不是逗号分隔。
$('input').live("touchmove touchend", function (e) {
I think this would work 我认为这会工作
$('x').live("ontouchmove, ontouchend", function (e) {
//do stuff
if (e.type == 'ontouchmove'){
//do stuff
}
else{
//do stuff
}
});
First off, your event variable should be the parameter e
rather than event
. 首先,您的事件变量应该是参数
e
而不是event
。
Second, when testing for equality, you need two equals signs: ==
. 其次,在测试相等性时,您需要两个等号:
==
。 One equals sign is the assignment operator. 一个等号是赋值运算符。
What does the console say when you open your site / trying to run the method? 当您打开网站/尝试运行该方法时,控制台会说些什么? :)
:)
//Gerner // Gerner
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.