1
在Backbone中我有以下模板,所有模板都完美呈現。在jQuery中綁定'touchstart'事件不支持android phonegap和backbone
<a href="#" data-role="button" id="button1" class="suggested-unselected"></a>
<script type="text/javascript">
document.getElementById('button1').addEventListener('touchstart', select, false);
function select(){
alert('test');
}
function unselect(){
alert('unselect');
}
</script>
它的工作原理:
<a href="#list" data-role="button" id="button" class="all-unselected"></a>
<a href="#" data-role="button" id="button" class="suggested-unselected"></a>
<a href="#" data-role="button" id="button" class="friends-unselected"></a>
<a href="#" data-role="button" id="button" class="private-unselected"></a>
<a href="#" data-role="button" id="button" class="buzz-unselected"></a>
<script type="text/javascript">
var buttons = $("a#button");
for(var i=0; i<buttons.length; i++){
$(buttons[i]).bind('touchstart', select, false);
$(buttons[i]).bind('touchend', unselect, false);
}
function select(){
alert('test');
}
function unselect(){
alert('unselect');
}
</script>
的touchstart不如果我寫了下面得不到然而觸發。就好像jQuery不能綁定事件一樣。可能是什麼問題?
我以前試過你的代碼。它仍然不起作用。在我看來,jQuery綁定到事件的方式是它期望的事件與實際觸發的touchstart不同。我確保刪除我的非工作代碼,以防止其他代碼無法正常運行。 – mabounassif 2012-04-03 07:55:39
@mabounassif它工作正常[我和其他人](http://stackoverflow.com/questions/7018919/how-to-bind-touchstart-and-click-events-but-not-respond-to-both) ,但是如果你確定'addEventListener',爲什麼你不使用它呢? – m90 2012-04-03 07:59:48