所以我有很多像这样的嵌入HTML代码:
<iframe src="http://www.mysite.com/embed/2049340993" frameborder="0" width="608" height="468" scrolling="no"><a href="http://www.mysite.com/view_video.php?viewkey=2049340993">
我想把它们放在不同的变量中但是我必须转义所有这样的字符:
var embedSource = "<iframe src=\"http://www.mysite.com/embed/2049340993\" frameborder=\"0\" width=\"608\" height=\"468\" scrolling=\"no\"><a href=\"http://www.mysite.com/view_video.php?viewkey=2049340993\">";
有没有更快的方法来实现这个目标?
答案 0 :(得分:3)
在HTML中使用撇号(单引号)。这样你就不必逃避它。
答案 1 :(得分:2)
我会Replace带撇号的引号。
embedSource = embedSource.Replace("\"", "'");
或者,如有必要,
embedSource = embedSource.Replace("\"", "\'");
在JavaScript replace()
中,小写 r 。
答案 2 :(得分:0)
最好的方法是不要加双引号
var embedSource = "<iframe src='http://www.mysite.com/embed/2049340993' frameborder='0' width='608' height='468' scrolling='no'><a href='http://www.mysite.com/view_video.php?viewkey=2049340993'>";