在 Js cookie html 标签中消失了
In Js cookie html tags have gone
我在 js cookie 中有一个 html 文本。当我尝试获取 cookie 中的文本并将该文本设置为 html div 时,它会被编码。我试图解码 html 但没有用。
这是我的代码:
function addToCoupon(team1,team2,id,bet,rate){
var betTableContent=$('#bet_table').html();
var row="<tr><td>"+team1+"-"+team2+"</td><td>"+bet+"</td><td>"+rate+"</td></tr>";
betTableContent+=row;
$.cookie("coupon",betTableContent);
$('#bet_table').html(unescape($.cookie("coupon")));
}
我在#bet_table 中的文本看起来与是否使用 unescape() 函数无关紧要:
%3Ctr%3E%3Ctd%3EHapoel%20Nazareth%20Elite-Maccabi%20Herzliya%3C%2Ftd%3E%3Ctd%3E1X2
那么如何才能正常显示此 html 文本 html?
在创建之前转义它,然后像这样取消转义
jQuery.cookie('coupon', escape('<html></html>'));
console.log(unescape(jQuery.cookie('coupon')));
我在 js cookie 中有一个 html 文本。当我尝试获取 cookie 中的文本并将该文本设置为 html div 时,它会被编码。我试图解码 html 但没有用。
这是我的代码:
function addToCoupon(team1,team2,id,bet,rate){
var betTableContent=$('#bet_table').html();
var row="<tr><td>"+team1+"-"+team2+"</td><td>"+bet+"</td><td>"+rate+"</td></tr>";
betTableContent+=row;
$.cookie("coupon",betTableContent);
$('#bet_table').html(unescape($.cookie("coupon")));
}
我在#bet_table 中的文本看起来与是否使用 unescape() 函数无关紧要:
%3Ctr%3E%3Ctd%3EHapoel%20Nazareth%20Elite-Maccabi%20Herzliya%3C%2Ftd%3E%3Ctd%3E1X2
那么如何才能正常显示此 html 文本 html?
在创建之前转义它,然后像这样取消转义
jQuery.cookie('coupon', escape('<html></html>'));
console.log(unescape(jQuery.cookie('coupon')));