zoukankan      html  css  js  c++  java
  • 操作IFRAME及元素

    内容里有两个ifame 
    <iframe id="leftiframe"...</iframe> 
    <iframe id="mainiframe..</iframe> 
    leftiframe中jQuery改变mainiframe的src代码: 
    $("#mainframe",parent.document.body).attr("src","http://www.jb51.net ") 
    如果内容里面有一个ID为mainiframe的ifame
    <iframe id="mainifame"...></ifame> 
    
    ifame包含一个someID
    <div id="someID">you want to get this content</div> 
    
    得到someID的内容 
    
    $("#mainiframe").contents().find("someID").html() html 或者 $("#mainiframe").contains().find("someID").text()值 
    
    如上面所示 
    leftiframe中的jQuery操作mainiframe的内容someID的内容
    $("#mainframe",parent.document.body).contents().find("someID").html()或者 $("#mainframe",parent.document.body).contents().find("someID").val() 
    
    
    在父窗口中操作 选中IFRAME中的所有单选钮
    
    
    $(window.frames["iframe1"].document).find("input[ at type='radio']").attr("checked","true");
    
    在IFRAME中操作 选中父窗口中的所有单选钮
    
    $(window.parent.document).find("input[ at type='radio']").attr("checked","true");
    iframe框架的:<iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
    
    IE7中测试通过
    在父页面访问Iframe子窗体的txtAddress控件
    window.frames["ifrMapCompanyDetails"].document.all("txtAddress").value = '地址' ; 
     
    在Iframe子窗体1访问父页面的TextBox1控件 , 子窗体1把值赋给子窗体2的某个控件 
    
    string strValue = "从子窗体传递给父页面的值" ; 
    
    下面是在Page_Load事件里面调用的,当然可以写在javascript脚本里面 
    
    this.Response.Write("<script>parent.document.all('TextBox1').value = '" + strValue + "';</script>"); 
    this.Response.Write("<script>if( parent.document.all('TextBox2').value = '0')parent.document.all('TextBox1').value = '44';</script>"); 
    
    子窗体访问父窗体中的全局变量:
    parent.xxx; 
    
    在Iframe子窗体1访问子窗体2的txtAddress控件 子窗体1把值赋给子窗体2的某个控件 
    
    window.parent.frames["ifrMapCompanyDetails"].document.all("txtAddress").value = '地址' ; 
    
    父窗体提交两个Iframe子窗体 
    
    window.frames["ifrMapCompanyDetails"].Form1.submit(); 
    window.frames["ifrMapProductInfoDetails"].Form1.submit(); 
    
    Iframe子窗体 调用父页面的javascript事件
    window.parent.XXX() 

    父页面调用当前页面中IFRAME子页面中的脚本childEvent
    function invokechildEvent() 
    { var frm = document.frames["ifrChild1"].childEvent(); } 
    或者调用当前页面中第一个IFRAME中的脚本childEvent
    { var frm = document.frames[0]; frm.childEvent(); } 

    子页面调用父窗体的某个按钮的按钮事件
    window.parent.Form1.btnParent.click() 
    
    父页面调用子窗体的某个按钮的按钮事件
    window.frames['ifrChild1'].document.all.item("btnChild3").click(); 
     
    在父窗口中操作 选中IFRAME中的所有单选钮
    $(window.frames["iframe1"].document).find("input[ at type='radio']").attr("checked","true"); 
    在IFRAME中操作 选中父窗口中的所有单选钮 
    $(window.parent.document).find("input[ at type='radio']").attr("checked","true");
     
  • 相关阅读:
    idea启动tomcat服务失败
    500错误 javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [happy] is not bound in this Context. Unable to find [happy].
    idea启动tomcat服务失败 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild:
    浅谈注解式开发
    PTA编程总结3
    PTA编程总结2
    PTA编程总结1
    秋季学期学习总结
    Git简明教程
    Linux常用软件安装
  • 原文地址:https://www.cnblogs.com/gxsyj/p/6008635.html
Copyright © 2011-2022 走看看