简体   繁体   English

单引号,双引号,加号登录Javascript

[英]Single quote, double quote, plus sign in Javascript

I'm not good in JS. 我不擅长JS。 I tried to modify a jQuery plugin from these codes: 我试图从这些代码修改jQuery插件:

aTag +=  " style='"+innerStyle+"'";
aTag += arrow + '<span>text here</span>';

to these codes: 这些代码:

//aTag +=  " style='"+innerStyle+"'";
aTag += arrow + '<span style="'+innerStyle+'">text here</span>';

Basically I want to move the content of innerStyle from anchor tag to span tag. 基本上我想将innerStyle的内容从anchor标签移动到span标签。 However, in Firebug I saw this mess after the move: 然而,在Firebug中,我看到移动后的这个烂摊子:

<span blue;"="" solid="" 1px="" border:="" 25px;="" text-indent:="" transparent;="" -80px="" 5px="" scroll="" no-repeat="" image.png")="" images="" web="" 127.0.0.1="" http:="" style="background: url(">text</span>

Why it works in anchor tag but not in span tag? 为什么它在锚标签中有效但在span标签中没有? What's the use of plus (+) signs? 加号(+)有什么用?

+ does just what it looks like it does in this case (concatenate text). +做了它在这种情况下的样子(连接文本)。 The issue here is that the HTML that is being generated in the first instance looks like this: 这里的问题是在第一个实例中生成的HTML如下所示:

style='some contents with a " symbol'

while in the second case what is being generated is this: 而在第二种情况下,生成的是:

style="some contents with a " symbol"

... which, as you can see, is broken - change your code to: ...正如您所看到的那样,它已被破坏 - 将您的代码更改为:

aTag += arrow + "<span style='" + innerStyle + "'>text here</span>";

and it will work. 它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM