我遇到了jQuery 1.6.4,iOS 5以及touchstart/touchend事件(正如標題中所述,顯然)的註冊問題。iOS 5上的jQuery事件
看看下面的代碼:
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="mmpa/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $body = $('body');
$('<button>').html('test jQuery').bind('touchstart', function() { alert('touchstart'); }).appendTo($body);
});
</script>
</head>
<body>
<button ontouchstart="alert('touchstart');">test pure JS</button>
</body>
</html>
「純JS」 按鈕顯示的iOS 4.3和iOS 5的警報,但 「jQuery的」 按鈕僅適用於iOS 4.3。 在iPad/iPhone模擬器4.3和5上測試;也在真正的iPhone 4.3,iPhone 5.0和iPad 5.0上進行測試。 如果我使用<input type="button">
或者甚至是簡單的<a>
而不是<button>
,則會出現相同的反應。
這是一個與jQuery相關的問題,我相信嗎?
不使用綁定(「touchstart」)和ontouchstart =「」。使用其中之一,並且不要使用內聯JavaScript。 –
這是一個概念證明,表明內聯JS在jQuery沒有的情況下工作。當然,我從來沒有在實際代碼中使用內聯JS。 – Cyrille
我可以用jQ 1.5.2和click事件產生這個錯誤,所以也許你應該修改標題爲「iOS 5上的jQuery事件」 – webXL