VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > JavaScript教程 >
  • jquery/js iframe 元素操作

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的内容)

1
2
3
4
5
6
<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的父类元素

1
2
3
4
<scritp>
    $('#父窗口中的元素ID', parent.document).click();
    $('#btnOk', parent.document).click(); 
</script>
回到顶部

 5.jquery 子元素 获取当前iframe的id

1
2
3
4
<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
</script>
回到顶部

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
</script>
回到顶部

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是否加载完成

1
2
3
$("#myFrameName").load(function () { //myFrameName iframe 的id
    //加载完成
    });

 

回到顶部

10,在父页面判断子页面被点击:

1
2
3
4
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 的函数

1
2
var x = $("iframe id")[0].contentWindow;
x.functionName()
回到顶部

14.iframe 调用 父页面的 Js 变量;

1
2
3
parent.method
 
parent.variable
回到顶部

 15.select 默认显示

http://www.cnblogs.com/colaman/p/9719681.html

回到顶部

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     b.getElementById("jkxxTabs");

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

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

  2、contentDocument  Firefox 支持,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();


 

 

 

 

 

 

 

 

 

 

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

来源:https://www.cnblogs.com/lixiuming521125/p/9744983.html

相关教程