jQuery使用总结
发布日期:2021-06-29 02:17:11
浏览次数:2
分类:技术文章
本文共 3648 字,大约阅读时间需要 12 分钟。
1.JS/jquery获取iframe内部元素和ifame中获取外部元素
1、从外部获取iframe内部元素方法:
js : window.frames['frame'].document.getElementById("imglist"); //frame为iframe的name值/ID值。 jq : $(window.frames['frame'].document.getElementById("imglist")); //frame为iframe的name值/ID值。
2、从内部获取外部的元素方法:
js :window.parent.document.getElementById("btnOk"); jq : $("#confirmq",parent.document);
3. 导航-右侧部分的标签栏内容变化监测事件
// 导航-右侧部分的标签栏内容变化监测事件$("nav[class='page-tabs J_menuTabs']").on('DOMNodeInserted',function() {// 标签栏内部新增元素的监测函数 $("#page-wrapper .active J_menuTab,.J_menuTab").each(function(){// 遍历对象内部的元素 var tabInfo =$(this);// 获取对象 var tabInfoName = tabInfo.context.textContent; var menuTab_name = document.getElementById("menuTab_name"); menuTab_name.value = tabInfoName; console.log(tabInfo); console.log(menuTab_name); })})
4.获取ifamr框架外元素的对象
// 点击页面按钮后获取按钮的相关信息--begin$("button,.toolStripButton,page-wrapper .J_menuTab,.active J_menuTab").mousedown(function() { var buttonInfo =$(this); var buttonInfoName = buttonInfo.context.textContent; var kx_btn_name = document.getElementById("kx_btn_name"); kx_btn_name.value = buttonInfoName; console.log(buttonInfo); console.log(kx_btn_name); $("#page-wrapper .active.J_menuTab",parent.document).each(function(){ var tabInfo =$(this); var tabInfoName = tabInfo.context.textContent; var kx_menuTab_name = document.getElementById("kx_menuTab_name"); kx_menuTab_name.value = tabInfoName; console.log(tabInfo); console.log(kx_menuTab_name); })})
5.Jquery取得iframe中元素的几种方法Javascript Jquery获取Iframe的元素、内容或者ID
在iframe子页面获取父页面元素
代码如下: $('#objId', parent.document); // 搞定...在父页面 获取iframe子页面的元素
代码如下: $("#objid",document.frames('iframename').document)$(document.getElementById('iframeId').contentWindow.document.body).html()
显示iframe中body元素的内容。 $("#testId", document.frames("iframename").document).html();根据iframename取得其中ID为"testId"元素 $(window.frames["iframeName"].document).find("#testId").html()用JS或jQuery访问页面内的iframe,兼容IE/FF 注意:框架内的页面是不能跨域的! 假设有两个页面,在相同域下. index.html 文件内含有一个iframe: XML/HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>页面首页</title> </head> <body> <iframe src="iframe.html" id="koyoz" height="0" width="0"></iframe> </body> </html> iframe.html 内容: XML/HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>iframe.html</title> </head> <body> <div id="test">www.koyoz.com</div> </body> </html> 1. 在index.html执行JS直接访问: JavaScript代码 document.getElementById('koyoz').contentWindow.document.getElementById ('test').style.color='red' 通过在index.html访问ID名为'koyoz'的iframe页面,并取得此iframe页面内的ID为'test'的 对象,并将其颜色设置为红色. 此代码已经测试通过,能支持IE/firefox . 2. 在index.html里面借助jQuery访问: JavaScript代码 $("#koyoz").contents().find("#test").css('color','red'); 此代码的效果和JS直接访问是一样的,由于借助于jQuery框架,代码就更短了. 收集网上的一些示例: 用jQuery在IFRAME里取得父窗口的某个元素的值 只好用DOM方法与jquery方法结合的方式实现了1. 在父窗口中操作 选中IFRAME中的所有单选钮 $(window.frames["iframe1"].document).find("input:radio").attr("checked","true");2. 在IFRAME中操作 选中父窗口中的所有单选钮 $(window.parent.document).find("input:radio").attr("checked","true"); 父窗口想获得IFrame中的Iframe,就再加一个frames子级就行了,如: $(window.frames["iframe1"].frames["iframe2"].document).find("input:radio").attr("checked","true");3.在子窗口中调用父窗口中的另一个子窗口的方法(FRAME):
parent.frames["Main"].Fun();
注意:建议使用[],这样比较兼容多个浏览器,() 火狐/搜狗/谷歌不兼容。
转载地址:https://blog.csdn.net/ywyngq/article/details/102758794 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月08日 04时12分05秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
[经典排序算法][集锦]
2019-04-29
无处不在的二分查找
2019-04-29
Java集合框架List,Map,Set等全面介绍
2019-04-29
Java 泛型(二) 泛型之中的通配符(Wildcards)使用
2019-04-29
7-36 复数四则运算 (15 分)
2019-04-29
基于powershell的渗透测试工具nishang
2019-04-29
Linux免密码登录设置
2019-04-29
JVM命令使用演示
2019-04-29
面试中并发类问题的准备和学习
2019-04-29
2018 Java 后端工程师的书单推荐
2019-04-29
使用IPVS实现Kubernetes入口流量负载均衡
2019-04-29
ETCD原理详细解析
2019-04-29
Docker 快速删除所有容器
2019-04-29
分布式锁的实现方式
2019-04-29
JVM性能监控工具-Jvisualvm
2019-04-29
JMX超详细解读
2019-04-29
Java泛型详解
2019-04-29
Hadoop集群hdfs添加磁盘操作
2019-04-29
【运维篇】HDFS磁盘选择策略详解
2019-04-29