简体   繁体   中英

checking jquery.cookie values

I'm creating a to-do-list web app, which sets each to-do as a cookie. I'm trying to loop through jQuery.cookie values to separate out my cookies into 'to-do' and 'done'.

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

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返回-1 ,这是一个真实值,因此您需要检查索引是否大于-1以测试是否在字符串中找到该项目。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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