0

我正在尝试使用以下代码将经度和纬度数据加载到 cookie 中:

$.cookie('test', 'test');
var test = true;

function PageLoaded() {
    if (test) {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(success_handler, error_handler, {
                enableHighAccuracy: true
            });
            test = false;
        }
    }
}

function success_handler(position) {
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
    accuracy = position.coords.accuracy;
    document.getElementById("tbLat").value = latitude;
    document.getElementById("tbLon").value = longitude;
    $.cookie('Latitude', latitude);
    $.cookie('Longitude', longitude);

}

function error_handler() {
    document.write('This browser does not support location awareness or you have declined to allow it to view your location.');
}

我正在加载 JQuery.Cookie.js 插件。第一个cookie“测试”正确加载,但后两个“纬度和经度”抛出错误

对象不支持属性或方法“cookie”

为什么是这样?

4

1 回答 1

-2

jQuery 没有cookie()函数。您忘记包含 cookie 插件 - https://github.com/carhartl/jquery-cookie

于 2012-04-26T17:38:32.303 回答