Home  >  Article  >  Web Front-end  >  javascript 获取iframe里页面中元素值的方法_javascript技巧

javascript 获取iframe里页面中元素值的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:59:511244browse

IE方法:
document.frames['myFrame'].document.getElementById('test').value;

火狐方法:
document.getElementById('myFrame').contentWindow.document.getElementById('test').value;

IE、火狐方法:

复制代码 代码如下:

    function getValue(){


         var tmp = '';


         if(document.frames){


                tmp += 'ie哥说:';


                tmp += document.frames['myFrame'].document.getElementById('test').value;


         }else{


                tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;


         }


         alert(tmp);


    }


示例代码:
a.html页面中的代码
复制代码 代码如下:


           
               
                <br>                    javascript 获取iframe里页面中元素的值 测试<br>               
          
          
               
               
               
           
       

b.html页面中的代码
复制代码 代码如下:

      
           
               
                <br>                    我是 iframe内的页面<br>               
           
           
               
           
         
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn