【问题标题】:load external html file to div using jquery使用jquery将外部html文件加载到div
【发布时间】:2012-01-13 11:11:55
【问题描述】:

我正在使用一个包含许多工具提示的 html 页面。每个工具提示都有一个画廊,因为不可能使用多个具有相同 id 的画廊,我打算为画廊创建 6 个不同的 html 文件,然后将画廊加载到我的默认页面中。

我需要为每个 div 调用 html 页面。 我试过 .load 但它不起作用。

<div id="flrmain">need to call the html file inside this div.<div>

请帮忙。

【问题讨论】:

  • “不工作”是什么意思?什么都没发生?你得到错误?并非所有内容都已加载?等请发布您尝试过的代码。
  • @Sowmya - 你让它工作了吗?
  • 不,它不工作!我在外部 html 中只添加了 div 部分(没有 doctype/body/html 标签)。尝试使用下面的代码,但没有在我的 div 中获取 html 页面。 $.get('timeless_op1.html') .success(function(data) { $('#flrmain').html(data); });

标签: jquery html load


【解决方案1】:
$.get('test.html')
 .success(function(data) {
     $('div.content').html(data);
 });

编辑

如果您对特定的div 需要它,请将'div.content' 替换为'#flrmain'

【讨论】:

  • 用你的url替换test.html(你也可以指定查询参数,查看jquery的文档)。
  • .success 已弃用,请改用.doneapi.jquery.com/jquery.get
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多