樣品字符串美元符號的Javascript str.replace所取代:與不工作
https://fw.adsafeprotected.com/rjss/bs.serving-sys.com/52023/7720220/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=1234567890&PluID=0&w=300&h=600&ord=[timestamp]&ucm=true&ncu=$${CLICK_URL_ENC}$&adsafe_preview=${IS_PREVIEW}`
替換我試圖讓:
$${CLICK_URL_ENC}$ --> $$${CLICK_URL_ENC}$$
[timestamp] --> ${CACHEBUSTER}
所需的輸出:
https://fw.adsafeprotected.com/rjss/bs.serving-sys.com/52023/7720220/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=1234567890&PluID=0&w=300&h=600&ord=${CACHEBUSTER}&ucm=true&ncu=$$${CLICK_URL_ENC}$$&adsafe_preview=${IS_PREVIEW}
代碼我已經試過:
代碼:
var v = $("textarea#creative-content").val();
v = v.replace(/\$\$\{CLICK\_URL\_ENC\}\$/g, "$$${CLICK_URL_ENC}$$");
v = v.replace("[timestamp]","${CACHEBUSTER}");
console.log(v);
輸出:
- 改變
[timestamp]
到${CACHEBUSTER}
:是 - 改變
$${CLICK_URL_ENC}$
到$$${CLICK_URL_ENC}$$
:沒有
代碼:
var v = $("textarea#creative-content").val();
v = v.replace("$${CLICK_URL_ENC}$", "$$${CLICK_URL_ENC}$$");
v = v.replace("[timestamp]","${CACHEBUSTER}");
console.log(v);
輸出:
- 改變
[timestamp]
到${CACHEBUSTER}
: 是 - 改變
$${CLICK_URL_ENC}$
到$$${CLICK_URL_ENC}$$
:沒有
代碼:
var v = $("textarea#creative-content").val();
v = v.replace("\$\${CLICK_URL_ENC}\$", "\$\$\${CLICK_URL_ENC}\$\$");
v = v.replace("[timestamp]","${CACHEBUSTER}");
console.log(v);
輸出:
- 變化d
[timestamp]
到${CACHEBUSTER}
:是 - 改變
$${CLICK_URL_ENC}$
到$$${CLICK_URL_ENC}$$
:沒有
我怎樣才能讓我在尋找使用JavaScript/jQuery的變化?
你[需要轉義'$'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String /替換#Specifying_a_string_as_a_parameter)以各種方式,因爲它是一個特殊的字符。 –
@JamesThorpe我試過了'v = v.replace(「\ $ \ $ {CLICK_URL_ENC} \ $」,「\ $ \ $ \ $ {CLICK_URL_ENC} \ $ \ $」);'沒有運氣...... – Ben
閱讀文檔 - 您不會使用\轉義它。 –