简体   繁体   中英

Javascript replacing characters

I have set up a table in which you enter a search term and it opens a amazon link, however to get multiple keywords I need to add an +.

i have used var removeSymb = split(' ').join('+'); to replace it with a space however the link does not work and needs the + .

Update:

var url = "www.amazon"+country+"/gp/community-content-search/results/ref=cm_srch_q_rtr/?qu‌​ery="+keyword1+"&search-alias=community-reviews&Go.x=-646&Go.y=-262&idx.asin="+as‌​in+"&tag=amazon-review0a-21";

I have a form with asin, country and then a form to enter keywords this is the final string:

var finalAddress1 = "amazon"+country+"/gp/community-content-search/results/…;

For the search to have multiple keywords you need to add + between them but I need to remove this so you use space but the + is entered in the hyperlink

How do I do this?

假设str是包含您的文本的字符串:

var removeSymb = str.replace(/\s/g,'+');

You can use Regex for this.

var string = ' ';
var reg = new RegExp(string, 'g');

str = str.replace(reg, '');

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