javascript replace()如何实现同时替换换行符和把指定的字变成别外要替换的字
我是这么写的:<script>functiontest(){vara=document.getElementById("t1").value;varb=window.op...
我是这么写的:<script>function test(){var a = document.getElementById("t1").value;var b = window.open();b.document.write(a.replace(/\n/g,"<br>"));b.document.write(a.replace(/[你;好;不好]/g,"要替换的字"));}</script><button onClick="javascript: test();">确定</button><hr><textarea id="t1" cols="100" rows="30"></textarea>效果如图(跟想要出现的效果不一样),请问正确的写是怎样的,非常感谢。
展开
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
<script>
function test() {
var a = document.getElementById("t1").value;
var b = window.open();
b.document.write(a.replace(/[\r\n\f]/g, "<br />"));
b.document.write(a.replace(/(你|好|不好)/g, "要替换的字"));
}
</script>
</head>
<body>
<textarea id="t1"></textarea>
<button onClick="test()">确定</button>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询