问题
I am using jqtouch to make a touch-optimized site. For iOS, I bind "tap" to the click listener, but this doesn't register in Android. I tried using touchend, which works, but it then overrides any sort of dragging (click on items when all a user is trying to do is scroll). What would I bind it to for Android? Here's my code:
var userAgent = navigator.userAgent.toLowerCase();
var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipad') != -1 || userAgent.indexOf('ipod') != -1) ? true : false;
var isAndroid = (userAgent.indexOf('android') != -1) ? true : false;
clickEvent = isiPhone ? 'tap' : 'click';
//NEED TO SET THIS UP FOR ANDROID, BUT 'TAP' DOESN'T WORK
$('.work_img').bind(clickEvent, function(event){
//DO STUFF ON CLICK / TAP
});
回答1:
Tap event working on my android 4.1 Samsung pocket phone
$(function() {
$('#tapme').bind('tap', function() {
$(this).parent().after('<li>tapped!</li>')
});
});
it works only when I include it inside
$(function() {
--- bind here --
});
and also for android, add this line
var jQT = new $.jQTouch({
useFastTouch: false
});
when u use jquery make sure these three are included (order matters!!)
<script src="jquery-1.7.min.js" type="text/javascript"></script>
<script src="jqt.min.js" type="text/javascript"></script>
<script src="jqtouch-jquery.min.js" type="text/javascript"></script>
with zepto
<script src="zepto.min.js" type="text/javascript" ></script>
<script src="jqt.min.js" type="text/javascript" ></script>
来源:https://stackoverflow.com/questions/6820863/javascript-equivalent-of-ioss-tap-event-but-for-android