gpt4 book ai didi

javascript - 如何将utf8编码的html嵌入到元素中

转载 作者:行者123 更新时间:2023-11-28 00:03:06 25 4
gpt4 key购买 nike

我有一个包含 html 标记的 UTF-8 编码字符串。我无法使用 jquery 成功将该 html 嵌入到 div 中 - 它总是最终呈现为字符串。我仅限于 v 1.7.2,因此无法查看 parseHTML 函数。

<div id="target"></div>
<script>
var tgt = $('#target');

tgt.html(resultingCode());


function resultingCode(){
return '%3Ctable%20width%3D%22650%22%20class%3D%22deviceWidth%22%20border%3D%220%22%20cellpadding%3D%220%22%20cellspacing%3D%220%22%20align%3D%22center%22%20bgcolor%3D%22%23eeeeed%22%3E%20%3Ctr%3E%20%3Ctd%20valign%3D%22top%22%20style%3D%22padding%3A0%22%20bgcolor%3D%22%23ffffff%22%3E%20%3Cp%20style%3D%22mso-table-lspace%3A0%3Bmso-table-rspace%3A0%3B%20padding%3A0px%3B%20margin%3A0%3B%22%3E%20%3Ca%20href%3D%22%23%22%3E%3Cimg%20src%3D%22http%3A%2F%2Fplacehold.it%2F650x350%26text%3DFULL%22%20alt%3D%22%22%20border%3D%220%22%20style%3D%22display%3A%20block%3B%20width%3A100%25%3B%20height%3Aauto%3B%22%2F%3E%3C%2Fa%3E%20%3C%2Fp%3E%20%3C%2Ftd%3E%20%3C%2Ftr%3E%20%3C%2Ftable%3E';
}
</script>

fiddle 在这里 - https://jsfiddle.net/carlv/ocmtaowz/2/

我被难住了 - 任何建议都非常感谢!

最佳答案

尝试让你的函数resultCode使用decodeURIComponent()

function resultingCode(){
return decodeURIComponent("%3Ctable%20width%3D%22650%22%20class%3D%22deviceWidth%22%20border%3D%220%22%20cellpadding%3D%220%22%20cellspacing%3D%220%22%20align%3D%22center%22%20bgcolor%3D%22%23eeeeed%22%3E%20%3Ctr%3E%20%3Ctd%20valign%3D%22top%22%20style%3D%22padding%3A0%22%20bgcolor%3D%22%23ffffff%22%3E%20%3Cp%20style%3D%22mso-table-lspace%3A0%3Bmso-table-rspace%3A0%3B%20padding%3A0px%3B%20margin%3A0%3B%22%3E%20%3Ca%20href%3D%22%23%22%3E%3Cimg%20src%3D%22http%3A%2F%2Fplacehold.it%2F650x350%26text%3DFULL%22%20alt%3D%22%22%20border%3D%220%22%20style%3D%22display%3A%20block%3B%20width%3A100%25%3B%20height%3Aauto%3B%22%2F%3E%3C%2Fa%3E%20%3C%2Fp%3E%20%3C%2Ftd%3E%20%3C%2Ftr%3E%20%3C%2Ftable%3E");
}

引用:decodeUriComponent

关于javascript - 如何将utf8编码的html嵌入到元素中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31601231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com