【问题标题】:JQuery: Way to add HTML code to a div?JQuery:将 HTML 代码添加到 div 的方法?
【发布时间】:2012-07-02 16:57:19
【问题描述】:

所以我有这个代码

if ($(this).is(".item")) {
    $("#hoverdiv").text("This div has the Item class<br>Test").show();
}

而且我发现了使用 .text 不会解析 HTML 代码的困难方法。有什么办法可以解决这个问题吗?

【问题讨论】:

  • 如果你知道 jQuery、html 和 parse 这三个词,你自己很容易找到。只是说

标签: jquery html parsing tags


【解决方案1】:

使用html 代替text

if ($(this).is(".item")){
    $("#hoverdiv").html("This div has the Item class<br>Test").show();
}

【讨论】:

    【解决方案2】:

    当您添加tags 时,您应该使用html() 而不是text()

    设置匹配元素集中每个元素的 HTML 内容。

    if ($(this).is(".item")){
          $("#hoverdiv").html("This div has the Item class<br>Test").show();
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 2013-07-12
      • 1970-01-01
      相关资源
      最近更新 更多