问题
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