我是 Coffeescript 的新手,并且在语法上苦苦挣扎。谁能帮助我如何用 CS 编写以下内容?
$("#getLocation").click(function() {
$('#location-loading').show();
navigator.geolocation.getCurrentPosition(applyLocation);
return false;
});
function applyLocation(location) {
$('#LogLongitude').val(location.coords.longitude);
$('#LogLatitude').val(location.coords.latitude);
alert('Latitude:' + location.coords.latitude + ', Longitude: ' + location.coords.longitude + ', Accuracy: ' + location.coords.accuracy);
$('#location-loading').hide();
}
我认为以下内容会起作用,但我在调用函数并返回 false 时遇到错误(所以我不关注链接)。
$('#getLocation').click ->
$('#location-loading').show()
navigator.geolocation.getCurrentPosition(applyLocation)
false
applyLocation = (location) ->
$('#LogLongitude').val(location.coords.longitude)
$('#LogLatitude').val(location.coords.latitude)
alert('Latitude:' + location.coords.latitude + ', Longitude: ' + location.coords.longitude + ', Accuracy: ' + location.coords.accuracy)
$('#location-loading').hide()