js实现整体,局部刷新

框架内外的按钮均可以定义网页重定向,

框架内部页面的按钮可以实现局部刷新,

框架外部页面的按钮可以实现整页刷新。

代码如下(两个html页面):

<!--主界面index.html-->
    <iframe src="页面刷新.html" frameborder="1"></iframe>
    <h1 id="iframeout">框架外内容</h1>
    <button onclick="fresh()">框架外刷新</button>
    
    <script>
        var h1 = document.getElementById('iframeout');
        function iframeout(){
            h1.style.color = "yellow";
            h1.innerText = "我变化了";
        }
        setInterval(iframeout, 800);//定时刷新
        function fresh(){
            // 框架主页面刷新,可以实现下面两个功能:
            top.location.reload();   //刷新整页 
            // window.parent.location.href='http://koushuling.top'; //框架页重定向 
        }
    </script>
<!--框架页面:页面刷新.html-->
   <style>
        body{
            background-color: gray;
        }
    </style>
   
    <h1 id="test">框架内页面</h1>
    <button onclick="fresh()">框架内刷新</button>

    <script>
        var h1 = document.getElementById('test');
        function test(){
            h1.style.color = "red";
            h1.innerText = "我变化了";
        }
        setInterval(test, 1000);
        function fresh(){
            // 框架内页面刷新:可实现局部刷新与整个页面重定向
             self.location.reload();  //刷新框架内页面
            // window.parent.location.href='http://koushuling.top'; //页面重定向 
        }
     </script>

 

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值