[英]Javascript encoding decoding problem
我有以下javascript
var cst = "\x26";
var other = $("#D1").html();
而且我的html具有D1 div,如下所示
<div id="D1">\x26</div>
現在,當我添加一個斷點並查看我的兩個變量cst和另一個時。 顯示一個&,另一個\\ x26。 也
cst.length == 1
但
other.length == 4
我很困惑。 我需要other的值相同(&),並且我不能更改Div。 我也在使用JQuery,因此可以使用$(div_id)
HTML不使用Javascript樣式的轉義字符串。
您的<div>
實際上是\\x26
,而不是&
。
嘗試這個。
var other = eval( "'" + $("#D1").html() + "'" );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.