0
試圖做一些事情,比如在我的論壇中使用html代碼。我想在使用[hidden]
字符串包裝時隱藏文本,並且在點擊按鈕之後,應顯示[hidden]
和[/hidden]
標籤之間的原始文本。我嘗試使用如何用javascript代替主字符串字符串
var res = str.replace("[hidden]$1[/hidden]", "$1");
試圖做一些事情,比如在我的論壇中使用html代碼。我想在使用[hidden]
字符串包裝時隱藏文本,並且在點擊按鈕之後,應顯示[hidden]
和[/hidden]
標籤之間的原始文本。我嘗試使用如何用javascript代替主字符串字符串
var res = str.replace("[hidden]$1[/hidden]", "$1");
你需要躲避支架,[]
,否則會被解釋爲character set。
var string = '[hidden]test[/hidden]';
string = string.replace(/\[hidden\](.*?)\[\/hidden\]/g, '$1');
// "test"
根據你的代碼,什麼將作爲文本收集器。我的意思是說,test
在上面是什麼意思。 –
看一看在文檔['String.prototype.replace'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace )和示例 – Andreas
PS:嘗試下一次提問,而不是僅僅發表聲明並顯示損壞的代碼;) –
另外,您可能希望使用現有的庫來支持BBCode等。沒有用的重新發明輪子。 –