开发者

How to update/append a string with javascript?

开发者 https://www.devze.com 2023-01-02 10:25 出处:网络
I want to check whether in querystring there is something like [?|&]rid=\\d, if there is,I want to update the \\d with a specific rid_value,

I want to check whether in querystring there is something like [?|&]rid=\d,

if there is,I want to update the \d with a specific rid_value,

else I want to append &rid开发者_Go百科=rid_value to querystring


pattern = /rid=\d/;
if(pattern.test(querystring)){
    querystring = querystring.replace(/rid=\d/, 'rid=' + rid_value);
} else{
    querystring = querystring + '&rid=' + rid_value;
}
0

精彩评论

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