Jquery插件在函数中不可用?

Jquery插件在函数中不可用?,jquery,Jquery,我正在尝试使用以下代码将经度和纬度数据加载到cookie中: $.cookie('test', 'test'); var test = true; function PageLoaded() { if (test) { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success_handler, error_handler, {

我正在尝试使用以下代码将经度和纬度数据加载到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“test”正确加载,但第二个cookie“Latitude&Longitude”抛出一个错误

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


这是为什么?

jQuery没有
cookie()
函数。您忘记在
success\u处理程序的中间包含cookie插件-

您切换到标准dom
getElementById
调用。为了保持一致,您可能应该坚持使用jQuery,
$('#tbLat')
try
jQuery.cookie('Longitude',Longitude)
@mgraph:这不会有任何影响。仅供参考…我可能应该为函数使用与“PageLoaded”不同的名称。它实际上是由onclick触发的。它是否到达jquery命名空间?其他jquery函数是否在该方法附件中工作?stacktrace怎么说?你能用简单的字符串(与纬度相反)吗?我正在加载cookie插件。啊,我的错。调用
PageLoaded()
的是什么?按钮上的一个简单onclick事件。