我试图将html文件包含在另一个html文件中,然后发出警报。
我在这里找到了一个解决方案。
来源请告诉我如何提醒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>
jQuery有一个获取其他网页的方便功能,$.get()
:
$.get('b.html', function(data) {
alert(data);
});
function(data) {}
是当http请求成功时运行的回调,data
将包含响应主体。