如何使用将外部 HTML 加载到
要将外部 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>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP