简体   繁体   English

JavaScript编码解码问题

[英]Javascript encoding decoding problem

I have the following javascript 我有以下javascript

 var cst = "\x26";
 var other = $("#D1").html();

And my html has D1 div like the following 而且我的html具有D1 div,如下所示

 <div id="D1">\x26</div>

Now when I add a breakpoint and see my two variables cst and other. 现在,当我添加一个断点并查看我的两个变量cst和另一个时。 One is shown & and another \\x26. 显示一个&,另一个\\ x26。 Also

cst.length == 1      

but

other.length == 4

I am confused. 我很困惑。 I need the value of other to be same (&) and I cannot change the Div. 我需要other的值相同(&),并且我不能更改Div。 I am also using JQuery so I can use $(div_id) 我也在使用JQuery,因此可以使用$(div_id)

HTML does not use Javascript-style escape strings. HTML不使用Javascript样式的转义字符串。

Your <div> actually says \\x26 , not & . 您的<div>实际上是\\x26 ,而不是&

尝试这个。

var other = eval( "'" + $("#D1").html() + "'" );

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

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