【问题标题】:I want to use a big html code in jquery我想在 jquery 中使用一个大的 html 代码
【发布时间】:2015-10-21 04:24:29
【问题描述】:

特别是方法 .append(html)。如何在追加中添加大的 html 代码,例如:

$("#results").append('<div class="some class"> ...a lot of html code... </div>')

【问题讨论】:

标签: jquery


【解决方案1】:

您可以将其存储在服务器上的 html 文件中,例如“template.html”并加载:

$("#results").load("/template.html");

如果 html 是静态的,这将起作用,但这引出了一个问题,为什么不能在包含 html 的页面上显示和隐藏一个 div。

但我猜你有更多的 jQuery 在将值附加到 #results 之前将其插入到 html 中,如果是这样,也许你可以使用类似 https://github.com/janl/mustache.js 的东西

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2018-01-26
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多