[英]Stripping spaces (%20) from JavaScript
如何從以下代碼中刪除空格( %20
)?
var newTab = {"url": config.searchEngines[newTabIndex].url.replace(new RegExp("%s", "g"), info.selectionText).replace(new RegExp("%S", "g"), info.selectionText)}
selectionText
是在網頁上突出顯示的電話號碼。 顯然,在數字上加20
會導致數字變得不正確。
查看decodeURIComponent()
函數http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp
var uri = config.searchEngines[newTabIndex].url,
newTab = {"url": decodeURIComponent(uri)};
只需刪除空格而不是替換為%20
,除非它們是字符串的一部分或在var
之后。
請改用它
str=str.replace(/%20/g,"")
所以對你的代碼
var newTab = {"url": config.searchEngines[newTabIndex].url.replace("%20", ""), info.selectionText).replace(/%20/g,""), info.selectionText)}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.