2012-06-06 11 views
11

tratando de obtener el valor de cookie si se establece y actualiza un div con el cookie valor; de lo contrario, generar un número aleatorio entre 80-100, configurarlo como cookie, y luego actualizar el div.Función de objeto (a, b) {return new e.fn.init (a, b, h)} no tiene el método 'cookie'

im conseguir el error:

Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie' 

aquí está mi código:

$(document).ready(function(){ 

    var thecounter = ''; 

    if ($.cookie('thecounter') == null) 
    { 
     thecounter = $.randomBetween(80, 100); 
     $.cookie('thecounter', thecounter, { path: '/' }); 
    } 
    else 
    { 
     thecounter = $.cookie('thecounter'); 
    } 

    $('dd-counter-num').html(thecounter); 

    setTimeout(newtime, 5000); 

}); 

function newtime() { 

    var newtime = $.cookie('thecounter') + $.randomBetween(1, 2); 
    $.cookie('thecounter', newtime, { path: '/' }); 
    $('dd-counter-num').html(newtime); 
    setTimeout(newtime, 5000); 

} 
+0

Parece que este fue el plugin que estabas buscando: https://github.com/carhartl/jquery-cookie pensé que podría añadir que ya que esto me ayudó también. –

Respuesta

14

No hay cookie método estándar en jQuery.

¿Quizás el código requiera jquery-cookie u otro complemento?

Happy coding.

+1

pensé que el método estaba integrado en jquery de un tutorial que leí que no incluía la URL del complemento. Encontré el complemento y funciona ahora. gracias. – scarhand

+0

hola scarhand ... ¿de dónde sacaste el plugin jquery-cookie? – antnewbee

+0

aquí está el complemento: http://plugins.jquery.com/cookie/ – ezawadzki

2

Asegúrese de hacer referencia a jquery.cookie.js después de cualquier referencia estándar de jquery.

I encountered this error when editing a page using Foundation . It was first loading jquery, then jquery.cookie.js, then the foundation.min.js file. I didn't realize was the custom foundation.min.js file already had jquery built-in, so executing JQuery again was causing the cookie javascript to fail.

Cuestiones relacionadas