js判断cookie是否存在

function getUsername() {
    var flag= document.cookie.indexOf("username=");
    if (flag==-1) {
        $.ajax({
            url:url+'cmd=Z_STZB_005',
            type:'post',
            dataType:'json',
            async:false,
            success:function (data) {
                $("#username").html(data.username);
                $.cookie("username", data.username);
            }
        });
    } else {
        $("#username").html($.cookie("username"));
    }
}

你可能感兴趣的:(jquery)