简体   繁体   English

检查jquery.cookie值

[英]checking jquery.cookie values

I'm creating a to-do-list web app, which sets each to-do as a cookie. 我正在创建一个待办事项Web应用程序,它将每个待办事项设置为cookie。 I'm trying to loop through jQuery.cookie values to separate out my cookies into 'to-do' and 'done'. 我正在尝试遍历jQuery.cookie值,以将Cookie分为“待办事项”和“完成”。

I'm working with this code which at the moment gets all of the cookies, if the key is numeric then it will append the items to my tbody 我正在使用此代码,该代码目前会获取所有cookie,如果密钥是数字,则它将把这些项附加到我的tbody

var obj = $.cookie();

// add each one to the list!
$.each( obj, function( key, value ){

    if ( $.isNumeric(key) ) {

        // display the table
        $('.grid-100').animate({
            opacity: 1
        }, 300);

        // hide the intro page
        $('.introduction').hide();

        if( value.indexOf('class="done green"') ) {
            // append to tfoot                  
            $('tfoot').append(value);
        } else {
            // append to tbody                  
            $('tbody').append(value);
        }


    } else {

        // do nothing.

    }

});

However this doesn't work, all of my to-do's get appended to tfoot even if they don't have an indexOf class="done green . 但这是行不通的,即使我的所有待办事项都没有indexOf class="done green也要附加到tfoot

如果未找到该项目, indexOf返回-1 ,这是一个真实值,因此您需要检查索引是否大于-1以测试是否在字符串中找到该项目。

if( value.indexOf('class="done green"') >= 0 ) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM