【问题标题】:jQuery load() div that contains a script包含脚本的 jQuery load() div
【发布时间】:2013-04-20 14:30:58
【问题描述】:

我正在尝试使用 load() 将包含 javascript 链接的 div 加载到另一个页面 (http://www.thebigkerbang.com/brand-storytellers/clients/xour-clients.html) 上的另一个 div 中。我知道 load() 去掉了脚本标签,但我对 $.getscript 有点困惑。我可以很好地加载 div,因为我可以在代码检查器中看到它。

从此页面加载 div:

 <div id="beautific_hype_container" style="position:relative;overflow:hidden;width:700px;height:500px;"> 
    <script type="text/javascript" charset="utf-8" src="beautific.hyperesources/beautific_hype_generated_script.js?10913"></script> 
  </div>

从此页面进入 div:

<div class = "edgeContent"></div>

与:

 $('document').ready(function(){
  $(".beautific").click(function(){
    $(".edgeContent").load('beautific/beautific.html #beautific_hype_container', function() {   
    $.getScript('beautific/beautific.hyperesources/beautific_hype_generated_script.js?10913');
        });
      });
    });

【问题讨论】:

  • 你怎么糊涂了?什么不工作?
  • 谢谢弗雷德里克。这仍然只加载&lt;div id="beautific_hype_container" style="position:relative;overflow:hidden;width:700px;height:500px;"&gt; &lt;/div&gt;并删除脚本。
  • 奇怪,我自己用那个方法,脚本没有过滤掉。再说一遍 - 我没有用 src 引用脚本,我有它内联。
  • 如果您查看浏览器开发者工具,从服务器收到的响应是什么?
  • 抱歉 Fredrik,它现在似乎正在使用脚本拉入 div。 (thebigkerbang.com/brand-storytellers/clients/xour-clients.html) 当您单击下面的第一个按钮时。 :) 感谢您的耐心等待,我对 $.ajax 了解一些 :)

标签: jquery load getscript


【解决方案1】:

我会通过$.ajax() 来电:

$('document').ready(function(){
  $(".beautific").click(function(){
    $.ajax({
      url: "beautific/beautific.html #beautific_hype_container",
    }).done(function ( data ) {
      $(".edgeContent").html(data);
    });
  });
});

这样你的脚本标签也不会被过滤掉。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2016-03-20
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2022-01-20
    相关资源
    最近更新 更多