如何在不花费太多时间转义变量的情况下,将长html代码放入变量中

如何在不花费太多时间转义变量的情况下,将长html代码放入变量中,html,Html,所以我有很多嵌入的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 embed

所以我有很多嵌入的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\">";
var-embedSource=”“;
有没有更快的方法来实现这一点呢?

我会在引号中加上撇号

embedSource = embedSource.Replace("\"", "'");
或如有需要,

embedSource = embedSource.Replace("\"", "\'");
在JavaScript中,
replace()
有一个小写的r

我会在引号中加上撇号

embedSource = embedSource.Replace("\"", "'");
或如有需要,

embedSource = embedSource.Replace("\"", "\'");

在JavaScript中,
replace()
有一个小写的r

在HTML中使用撇号(单引号)。这样你就不必逃避了。

在HTML中使用撇号(单引号)。这样你就不必逃避了。

最好的办法是不要用双引号

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'>";
var-embedSource=”“;

最好的方法是不要用双引号

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'>";
var-embedSource=”“;

如果您只需转义
(双引号),则类似于
embedSource=embedSource.Replace(“\”,“\\\”)应该可以工作。我认为你需要在结尾添加一个额外的“C”和asp经典标记-哪一个是错误的?(答案暗示asp.Net,如果你真的喜欢原始的asp,请适当地标记语言)。如果你所需要做的就是避开
(双引号),类似于
embedSource=embedSource.Replace(“\”,“\\”)
应该可以。我想你需要在最后加一个“C”和asp经典标记-哪一个错了?(答案意味着ASP.Net,如果你真的喜欢原始ASP,请适当地标记语言)。我宁愿在JavaScript中使用单引号。我宁愿在JavaScript中使用单引号。