简体   繁体   English

如何在另一个 html 文件中包含 html 文件,然后通过 javascript jquery 警报结果

[英]How to include html file in another html file and then alert result via javascript jquery

Am trying to include html file in another html file and then alert result.我试图将 html 文件包含在另一个 html 文件中,然后发出警报结果。

I found a solution here.我在这里找到了解决方案。

Source Please how do I alert the content of b.html instead of calling it in div. 请我如何提醒b.html的内容而不是在 div 中调用它。
something like就像是

alert('b.html content here');

a.html:一个.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: b.html:

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

jQuery has a handy function for getting other webpages, $.get() : jQuery 有一个方便的函数来获取其他网页, $.get()

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

function(data) {} is a callback which runs when the http request is made successfully, and data will contain the response body. function(data) {}是在 http 请求成功时运行的回调, data将包含响应正文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM