iframe局部刷新 发表于 2017-01-02 通过iframe实现全局刷新和局部刷新。 原理通过location.reload()来实现.详见代码。 代码主页面1234567891011121314151617181920212223<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head><body> <button>全局刷新</button> <iframe src="sub.html" frameborder="0" width="400" height="" scrolling="auto"></iframe> <script> window.onload = function () { document.getElementsByTagName('button')[0].onclick = function(){ //location.reload(); //top.location.reload(); parent.location.reload(); console.log("index.html reload!"); } } </script></body></html> 子页面1234567891011121314151617181920212223<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head><body> <p> 测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本! </p> <button id="subtbn">局部刷新</button> <script> window.onload = function () { document.getElementById('subtbn').onclick = function(){ self.location.reload(); console.log("sub.html reload!"); } } </script></body></html> ------本文结束 感谢阅读------ 本文作者: luckyp 本文链接: https://luckyp.top/iframe局部刷新/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!