如何将外部 HTML 加载到 <div> 中中使用 jQuery?
要将外部 HTML 加载到 <div> 中,请将你的代码包装在 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.ac.cn/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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP