js 替换特殊符号
[]+()?^$等等里面要用到的特殊字符都要转义。 即在前面加 \
<textarea id="tarea1" style="width:300px;height:300px"></textarea>
<textarea id="tarea2" style="width:300px;height:300px"></textarea>
<input type="button" value="ok" id="btnok" onclick="btnok_click()" />
<script>
function btnok_click() {
debugger
var i = document.getElementById("tarea1").value;
var res = TransferString(i);
var t = document.getElementById("tarea2");
t.innerText = res;
}
function TransferString(content) {
debugger
var string = content;
try {
//string = string.replace(/[\r\n]/g, ",");
string = string.replace(/\^/g, "1");
} catch (e) {
alert(e.message);
}
return string;
}
</script>