var textTitle = “this is a test” var result = textTitle.replace(‘ ‘, ‘%20’);
但是替换功能在“”的第一个实例处停止,我得到了
结果: "this%20is a test"
"this%20is a test"
任何关于我哪里出问题的想法都确保它很简单。
您需要/g在那里,像这样:
/g
var textTitle = "this is a test"; var result = textTitle.replace(/ /g, '%20'); console.log(result);