意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

jquery/js iframe 元素操作

来源:恒创科技 编辑:恒创科技编辑部
2024-02-04 21:59:59
1.判断id/ class 是否存在?
<script>
$(function(){
if(("#id_name").length()>0){
//如果id 存在
}
})
</script>
2.jquery 判断 undefined
<script>
var exp = undefined;
if (typeof(exp) == "undefined")
{
alert("undefined");
}
</script>
3.jquery 获取iframe元素内容(父类窗口中获取iframe的内容)
<script>
//格式:
$("#iframe的ID").contents().find("#iframe中的控件ID").click();//jquery 方法1
//实例:
$("#ifm").contents().find("#btnOk").click();//jquery 方法1
</script>

父窗口中操作iframe:window.frames["iframeChild"].document //假如iframe的id为iframeChild

父窗口中操作iframe:$(window.frames["iframeChild"].document) //假如iframe的id为iframeChild1 $(window.frames["iframeChild"].document).find("#child")
4.在iframe中 获取iframe的父类元素
<scritp>
$('#父窗口中的元素ID', parent.document).click();
$('#btnOk', parent.document).click();
</script>
5.jquery 子元素 获取当前iframe的id
<scritp>
self.frameElement.getAttribute('id');
window.frameElement.id ;//jquery 子元素 获取当前iframe的id
</script>
6.jquer操作CSS
<script>
$(".rendering").children().eq(0).css("color","white");//css的操作 color:white
7.jquery 添加/移除clss

注意:jQuery在操作class的时候,一定要循环取class,否则,默认是处理第一个元素

<script>
$(this).parent().addClass("am-in");//添加class为 “am-in”的class
$(this).parent().removeClass("am-in");//移除class为 “am-in”的class
8.hover实现:
<script>
//鼠标移上去,移走的颜色
$(this).hover(function(){
$(this).children().eq(0).css("background-color","#0e90d2");
$(this).children().eq(0).css("color","#eee");
},function(){
$(this).children().eq(0).css("background-color","#ffffff");
$(this).children().eq(0).css("color","#6b6b6b");
})
</script>
9.jquery 判断iframe是否加载完成
$("#myFrameName").load(function () { //myFrameName iframe 的id
//加载完成
});


jquery/js iframe 元素操作

10,在父页面判断子页面被点击:
var iframe = document.getElementById('gislist');
iframe.contentDocument.onclick = function () {
iframe.contentWindow.parent.hideZKZ();
};

11.jquery 字符串分割

​var​​​ ​​arr = ​​​​'sss@vvv'​​​​.split(​​​​'@'​​​​);​

此时 arr为数组;

12.iframe自适应高度

<iframe src='/hnsl/baseinf/gislist.do' id='gislist' style='min-height:600px;width:100%;' onload='this.contentWindow.document.body.scrollHeight'></iframe>

13.当前页面 调用 iframe 的函数
var x = $("iframe id")[0].contentWindow;
x.functionName()
14.iframe 调用 父页面的 Js 变量;
parent.method

parent.variable
15.select 默认显示

​​javascript:void(0)​​

16.获取iframe中的js变量tree:
1 var tree = document.getElementById('projectIframe').contentWindow.tree;
2
3 或者
4
5 $("#divId").find("iframe")[0].contentWindow.tree;
17.当前iframe 获取 兄弟iframe
1  var iframe = window.parent.document.getElementById('monitor');//monitor为兄弟iframe的id
2 var b = iframe.contentWindow.document;
3 var temperature = b.getElementById("Temperature");
4

用iframe嵌套页面时,如果父页面要获取子页面里面的内容,可以使用contentWindow或者contentDocument,其区别如下:

contentWindow 这是个只读属性,返回指定的iframe的窗口对象。它虽然不是标准的一部分,但各个主流浏览器都支持。

IE6,IE7都不支持,IE8开始支持,需要如此访问 document.frames['J_mainframe'].document。

18.在iframe本页面,要操作这个iframe的父页面的DOM元素(即嵌套这个iframe的页面)可以用:

  window.parent、window.top(这里的TOP是获取的顶层,即有多层嵌套iframe的时候使用)

18.获取任意iframe的内容

window.frame["frameID"].contentWindow;

例如:iframe1(id:fram1) 中有iframe2, iframe2(id:fram2) 中有iframe3(id:fram3)

要求 iframe4获取iframe3中的 input的值 ,该input的ID为 inputId

window.frames["fram1"].contentWindow.$("#fram2")[0],contentWindow.$("#fram3")[0].find("inputId").val();


我从来不相信什么懒洋洋的自由。我向往的自由是通过勤奋和努力实现的更广阔的人生。 我要做一个自由又自律的人,靠势必实现的决心认真地活着。




上一篇: mac --snip 滚动截屏 下一篇: 手机怎么远程登录云服务器?