js转发斜线不打印 [英] js forward slash not printing
本文介绍了js转发斜线不打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个javascript函式,用html < br />
标签取代所有b,但它只会印出< br>
。
这里是函数:
pre $ var destination = source.replace(/ b / g,< br \\ \\ />中);
这行不通,是不是错误?如果是这样,有人可以告诉我怎么做吗?
字符串中没有
var destination = source.replace(/ b / g,< br />);
编辑
摆弄这段代码
function gettext(){
var input = document.getElementById(input)。value ;
var value = input.replace(/ b / g,< br />);
var output = document.getElementById(out)。value = value;
}
查看替换行
var value = input.replace(/ b / g,< br />);
它是一个不是正则表达式的字符串
/ b / g
它需要
var value = input.replace(/ b / g,< br />);
I want a javascript function to replace all the b's with an html <br />
tag but it's only printing <br>
.
Here is the function:
var destination = source.replace(/b/g,"<br \/>");
It doesn't work, is it wrong? If so, could someone please show me how to do it?
解决方案
Original
There is no reason for the \
in the string.
var destination = source.replace(/b/g,"<br/>");
Edit
Now you gave a sample fiddle with this code
function gettext(){
var input = document.getElementById("input").value;
var value = input.replace("/b/g","<br/>");
var output = document.getElementById("out").value = value;
}
Look at the replace line
var value = input.replace("/b/g","<br/>");
it is a string not a regular expression
"/b/g"
It needs to be
var value = input.replace(/b/g,"<br/>");
jsFiddle Example with your code
这篇关于js转发斜线不打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文