i have a url that has several parameters, and i want to replace them using JQuery (not javascript).
var str = "http://example.com/index.php?color=red&size=large&quantity=5";
var newQty = 10;
How can i change the quantity using JQuery ONLY if quantity exists as a parameter? How can i change a parameter that isn't at the end of the query string, such as size=large?
I prefer to use regex and .replace function, if anyone can help me with the proper code please... something like this.
var newStr = str.replace(REGEX, "quantity="+newQty);
var REGEX = /quantity\=[0-9]+/;
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.