做這樣的工作?
JS
function bindEventTouch(element) {
element.bind('tap taphold swipe swiperight swipeleft', function(event, ui) {
console.log('Event: '+event.type);
if(event.type == 'taphold') {
console.log('Was Event taphold?: '+event.type);
element.trigger('touchend');
}
});
element.bind('touchend', function(event, ui) {
console.log('Triggered touchend Event: '+event.type);
});
}
$('.displayEvent').each(function(){
bindEventTouch($(this));
});
HTML
<div data-role="page" id="home">
<div data-role="content">
<div id="display-event-1" class="add-border displayEvent">
<p>Tap, TapHold (for 1 second), Swipe, SwipeRight or SwipeLeft</p>
</div>
<br />
<div id="display-event-2" class="add-border displayEvent">
<p>Tap, TapHold (for 1 second), Swipe, SwipeRight or SwipeLeft</p>
</div>
<br />
<div id="display-event-3" class="add-border displayEvent">
<p>Tap, TapHold (for 1 second), Swipe, SwipeRight or SwipeLeft</p>
</div>
</div>
</div>
CSS
.add-border {
border-style:solid;
border-width:1px;
width:100%;
text-align:center;
}
謝謝超級詳細的探索 - 我對jsFiddle有點新 - 我試圖用我的iPhone打開URL,但是當我嘗試挖掘這些元素時沒有發生任何事件,我是否做錯了什麼? – Yanipan
確定它:) - 不是iphone上的console.log。我會改變它以提醒...謝謝! – Yanipan
您可以使用控制檯http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/DebuggingSafarioniPhoneContent.html –