如何使用 jQuery 将外部 HTML 加载到
中?

jqueryweb developmentfront end technology

要将外部 HTML 加载到

中,请将代码包裹在 load() 函数中。要在 jQuery 中将页面加载到 div 中,请使用 load() 方法。首先,添加要添加的网页。

以下是 new.html 的代码

<html>
<head>    
</head>
<body>
<p>This is demo text.<p>
</body>
</html>

示例

以下是添加上述页面的文件的代码片段,

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   
   $('#content').load("new.html");
});
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>

相关文章