头标记中的脚本标记 [英] Script tag in head tag

查看:87
本文介绍了头标记中的脚本标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试html5的地理定位功能。这是我的代码:



Hi,

I am trying out the geolocation feature of html5. Here is my code:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
        var lat = document.getElementById("latitude");
        var lon = document.getElementById("latitude");

        function getLocation()
        {
            if (navigator.geolocation)
            {
                navigator.geolocation.getCurrentPosition(showPosition);
            }
            else
            {
                x.innerHTML = "Geolocation is not supported by this browser.";
            }
        }

        function showPosition(position)
        {
            lat.value = position.coords.latitude;

            lon.value = position.coords.longitude;
        }

    </script>

</head>
<body>
    <form>
        <button id="GetGeoLocation" onclick="getLocation()">Get Geo Location</button><br/>
        Latitude: <label id="latitude" /> <br/>
        Longitude: <label id="longitude" />
    </form>
</body>
</html>





点击按钮,代码无法到达javascript。



谢谢

-

Sameer



On clicking the button the code does not reach the javascript.

Thanks
-
Sameer

推荐答案

我刚做了一个测试你的代码和java

脚本文件被调用



I just did a test on your code and the java
script files is getting called

function getLocation() {
    alert("GetLocaiton Function called");

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    }
    else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}





如果你的其他部分,你有x.innerHTML但没有名为'的元素'代码中的x'?



if your else part, you have x.innerHTML but there is no element called 'x' in your code ?


这篇关于头标记中的脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆