Iframe是一种嵌入网页的框架形式,Web页面可以通过更改嵌入的部分,达到部分内容刷新。
Iframe的用法与普通的标签元素DIV类似,可以指定在页面中嵌入的位置、颜色、界面布局等
一、iframe实现局部刷新方法一
<script type="text/javascript"> $(function(){ $("#a1").click(function(){ var name= $(this).attr("name"); $("#iframe").attr("src",name).ready(); }) $("#a2").click(function(){ var name= $(this).attr("name"); $("#iframe").attr("src",name).ready(); }) }) </script> <a href="#" id="a1" name="a1.html">1</a> <a href="#" id="a2" name="a2.html">2</a> <iframe src="/UploadFiles/2021-04-02/">当点a1时在iframe里显示a1.html的内容,点a2时在iframe里显示a2.html的内容
二、iframe实现局部刷新的方法二
<a href="a1.html" id="a1" name="a1.html" target="i">1</a> <a href="a2.html" id="a2" name="a2.html" target="i">2</a> <iframe src="/UploadFiles/2021-04-02/">备注: <form> 同样也有target属性,作用和<a>一样 这个方式如果<from>或<a>提交到某个Action中再跳转到a1.html中效果一样,如果在Action中有req.set或session.set,最后在iframe中同样可以显示出来。
三:iframe实现局部刷新的方法三:
<iframe src="/UploadFiles/2021-04-02/1.htm">方案一:用iframe的name属性定位
<input type="button" name="Button" value="Button" onclick="document.frames('ifrmname').location.reload()">或
<input type="button" name="Button" value="Button" onclick="document.all.ifrmname.document.location.reload()">方案二:用iframe的id属性定位
<input type="button" name="Button" value="Button" onclick="ifrmid.window.location.reload()">方案三:当iframe的src为其它网站地址(跨域操作时)
<input type="button" name="Button" value="Button" onclick="window.open(document.all.ifrmname.src,'ifrmname','')">方案四:通过和替换iframe的src来实现局部刷新
可以用document.getElementById("iframname").src="/UploadFiles/2021-04-02/">
示例代码如下:test.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> function partRefresh() { document.getElementById("iframe1Id").src = "a2.html"; // 方法一: 通过和替换iframe的src来实现局部刷新 } </script> </head> <body> <table border="1" width="90%" align="center"> <tr style="background: #F0F0E4"><td>方格1</td><td>方格2</td> <td>方格3</td> </tr> <tr> <td> <iframe src="/UploadFiles/2021-04-02/a1.html">以上内容给大家介绍了JavaScript中iframe实现局部刷新的几种方法汇总,希望大家根据自己的需求选择适合自己的,有任何问题欢迎给我留言,谢谢!
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年10月04日
2024年10月04日
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]
- 班得瑞原装进口《第九张新世纪专辑:微风山谷》1CD[APE/CUE分轨][331MB]
- 陈慧琳.2008-Love.Fighters演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 米志宏.1994-HAPPY1994【波丽佳音】【WAV+CUE】
- 潘美辰.2006-最冷的夏天(引进版)【美梦辰真】【WAV+CUE】
- 班得瑞原装进口《第十张新世纪专辑:月光水岸》1CD[APE/CUE分轨][277.2MB]
- 班得瑞原装进口《第十一张新世纪专辑:雾色山脉》1CD[APE/CUE分轨][291.6MB]
- 班得瑞原装进口《第十二张新世纪专辑:翡翠谷》1CD[APE/CUE分轨][307.9MB]
- 高卿尘.2024-情绪商店【Hahahai】【FLAC分轨】
- 王恩喆.2024-黄沙【KOOD】【FLAC分轨】