无法指定包含“>”的字符串变量

时间:2015-04-10 12:46:29

标签: javascript html

我正在为javascript变量分配一个字符串。但它会产生错误。

方法1

jquery = "<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js'></script>";
<!DOCTYPE html>
<html>
    <head>
          <title>old</title> 
    </head>
    <body>
    hai
    </body>
</html>

方法2

jquery = "<script src=";
                    jquery1 = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js";
                    jquery2 = "></script>";
                    console.log(jquery + jquery1 + jquery2);
<!DOCTYPE html>
<html>
    <head>
          <title>old</title> 
    </head>
    <body>
    hai
    </body>
</html>

输出

hai“;

为什么'“;'在字符串“hai”之后添加。

我该如何解决这个问题?请帮我理解..

0 个答案:

没有答案
相关问题