【发布时间】:2014-02-05 16:53:17
【问题描述】:
我是 Javascript 的初学者,我正试图让这个例子发挥作用。
这是一个简单的想法。
给定用户的位置,如果 Lat 为
发生的情况是 if 根本不起作用.. 为什么? didi 我需要创建一个新函数或将 if 放在其中一个。?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function initGeolocation()
{
if( navigator.geolocation )
{
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( success, fail );
}
else
{
alert("Sorry, your browser does not support geolocation services.");
}
}
function success(position)
{
document.getElementById('userLong').value = position.coords.longitude;
document.getElementById('userLat').value = position.coords.latitude
}
function fail()
{
// Could not obtain location
}
</script>
</head>
<body onLoad="initGeolocation();">
<FORM NAME="rd" METHOD="POST" ACTION="index.html">
User Longitude: <INPUT TYPE="text" NAME="Long" ID="userLong" VALUE=""><br>
User Latitude : <INPUT TYPE="text" NAME="Lat" ID="userLat" VALUE=""><br>
<script>
if (userLat < 50){
document.write(" Great")
}
else { document.write( "Not Great")}
</script>
</body>
</html>
【问题讨论】:
-
请阅读Meta上关于how to write a good title的信息。 “这行不通”不是一个好标题。 [自此评论以来,标题已被编辑。]
标签: javascript html geolocation