【问题标题】:How to include html file in another html file and then alert result via javascript jquery如何将 html 文件包含在另一个 html 文件中,然后通过 javascript jquery 发出警报结果
【发布时间】:2021-06-21 19:46:05
【问题描述】:

我试图将 html 文件包含在另一个 html 文件中,然后警告结果。

我在这里找到了解决方案。

Source 请问如何提醒 b.html 的内容而不是在 div 中调用它。

alert('b.html content here');

a.html:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("b.html"); 
alert('b.html content here');
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

b.html:

<p>This is my include file</p>

【问题讨论】:

    标签: javascript html jquery


    【解决方案1】:

    jQuery有一个方便的获取其他网页的功能,$.get():

    $.get('b.html', function(data) {
        alert(data);
    });
    

    function(data) {} 是一个回调,在 http 请求成功时运行,data 将包含响应正文。

    【讨论】:

      猜你喜欢
      • 2013-06-25
      • 2012-02-17
      • 1970-01-01
      • 2019-01-04
      • 2011-11-24
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多