开发者

jQuery cookie and replace function in C#

I'm creating a cookie with jQuery and, in IE 7, saving codes with "," to separate them, I receive the following message:

"Is not possible obtain value of the property 'r开发者_C百科eplace': the object is null or not defined"

$.cookie(
    "CompareList", 
    $.cookie("CompareList").replace("," + id + ",", ""), 
    { path: "/" }
);

TKX, in advance!


If your cookie doesn't exist yet, you can't read its value and do stuff to it. From looking at the cookie plugin source it returns null (not an empty string) if there's no such cookie, so "replace" will fail. How about

var cookie = $.cookie("CompareList");
if (cookie) {
    $.cookie("CompareList",cookie.replace("," + id + ",", ""), 
    { path: "/" });
}

Your replace snippet looks pretty suspect also. That is going to replace a string of form ",someid," with an empty string, is that really what you want?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜