主页面为main.html,点击在div添加html按钮id为btn,
div的id为viewDiv,要插入的本地html为new.html。
方法一:基于Jquery的DIV嵌套html(测试可用)
- <script src="js/jquery.js"></script>
- 1
- $(document).ready(function(){
- $("#btn").click(function(){
- $('#viewDiv').load('new.html');
- })
- })
- 1
- 2
- 3
- 4
- 5
点击按钮即可在div中添加new.html。
方法二:纯js方法。(亲测可用,推荐此方法)
- function load_home() {
- document.getElementById("viewDiv").innerHTML = '<object type="text/html" data="new.html" ></object>';
- }
- 1
- 2
- 3
- <button type="button" id="btn" onClick="javascript:load_home();" >确认</button>
- 1
方法三:iframe 方法(未测试)
- <div class="main-container" id="main" >
- <iframe src="new.html" frameborder="0">
- 您的浏览器不支持iframe,请升级
- </iframe>
- </div>
- 1
- 2
- 3
- 4
- 5
应该还有很多方法,如果大家有更好的方法,欢迎留言。
百度搜索“就爱阅读”,专业资料,生活学习,尽在就爱阅读网92to.com,您的在线图书馆!
来源: http://www.92to.com/bangong/2017/09-17/28632768.html