我有一個項目,它使我瘋狂,我有代碼做地理位置/方向,它的工作令人驚歎的everthing但ios7和我做了堆的研究,我明白它的一個問題與.click事件,我的代碼如下。jQuery的iPhone/ios7點擊事件vs觸摸
$(document).ready(function() {
var startingLocation;
var destination = "20 Papanui Rd, Christchurch Central, Christchurch 8011, New Zealand"; // replace this with any destination
$('.get-directions').click(function (e) {
e.preventDefault();
// check if browser supports geolocation
if (navigator.geolocation) {
// get user's current position
navigator.geolocation.getCurrentPosition(function (position) {
// get latitude and longitude
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
startingLocation = latitude + "," + longitude;
// send starting location and destination to goToGoogleMaps function
goToGoogleMaps(startingLocation, destination);
});
}
// fallback for browsers without geolocation
else {
// get manually entered postcode
startingLocation = $('.manual-location').val();
// if user has entered a starting location, send starting location and destination to goToGoogleMaps function
if (startingLocation != '') {
goToGoogleMaps(startingLocation, destination);
}
// else fade in the manual postcode field
else {
$('.no-geolocation').fadeIn();
}
}
// go to Google Maps function - takes a starting location and destination and sends the query to Google Maps
function goToGoogleMaps(startingLocation, destination) {
window.location = "https://maps.google.com/maps?saddr=" + startingLocation + "&daddr=" + destination;
}
});
});
HTML:
<!--#container -->
<div id="mapcontainer">
<div class="no-geolocation">
<p class="warning">Your browser does not support Geolocation. Please enter your postcode and click the button again.</p>
<input type="text" placeholder="Enter postcode or address" class="manual-location">
</div>
<a href="#" class="get-directions">Give me directions</a>
</div>
<!-- /#container -->
現在我曾與德勤一齣戲。
<script type='text/javascript' src="files/scripts/touche.min.js"></script>
<script>
$(document).ready(function() {
$('.get-directions').on('click', handleClicks);
});
</script>
所有我得到的是一個錯誤handleClicks is not defined
和一對夫婦沒有運氣其他哈克腳本和我在我的解決問題的技術能力結束。
嗨!我想'handleClicks'函數是在'touche.min.js'中定義的。 JS腳本是否正確加載? – Littm
感謝您的回覆,該網站正在使用jquery-1.11.0.min.js,它可以很好地處理圖像滑塊,因此我知道它在那裏並正在工作。 – webmonkey237
它可能是與另一個腳本衝突? – webmonkey237