HTML编码文本通过JS无法渲染

时间:2014-04-04 15:49:03

标签: javascript html

我想要在设计中包含一对三角形,这需要通过JS文件显示文本,但JS中的HTML编码文本无法呈现。有谁知道如何使这项工作?

感谢您的时间。


这是特定的文字:

  

网站▴网站▾

这里是JS:
(最后一行是:网站&#9652 网站&#9662

$(function() {
  $(".header").click(function () {

    $header = $(this);
    //getting the next element
    $content = $header.next();
    //open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
    $content.slideToggle(500, function () {
        //execute this after slideToggle is done
        //change text of header based on visibility of content div
        $header.text(function () {
            //change text based on condition
            return $content.is(":visible") ? "Websites ▴" : "Websites ▾";
        });
    });

  });
});

1 个答案:

答案 0 :(得分:1)

更改

$header.text(function () {
    //change text based on condition
    return $content.is(":visible") ? "Websites ▴" : "Websites ▾";
});

$header.html($content.is(":visible") ? "Websites ▴" : "Websites ▾");

.text()函数被HTML转义(再次)。此外,它没有功能。