如何使用JS 向Iframe的文本框中写入一个字符
如写入ABC,能不能给一个简单的例子,谢谢了

解决方案 »

  1.   

    a.htm<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>a</title>
    </head><body>
    <iframe src=b.htm onload="this.contentWindow.document.getElementById('txt1').value='从父页面写过来的'"></iframe>
    </body></html>
    b.htm<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>b</title>
    </head><body>
    <input type=text id="txt1">
    </body></html>
      

  2.   

    非常感谢两位,
    不好意思,我没写清楚,我的Iframe是别人的网站,怎么写入呢
      

  3.   

    lz可以自己搜搜“js 跨域”这里有篇文章:http://zhuhaifeng.javaeye.com/blog/437154
      

  4.   


    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>a</title>
    <script>
    window.onload = function () {
          window.frames["main"].document.getElementById("txt1").value = "bac";
    };window.frames["main"].onload = function () {
          window.frames["main"].document.getElementById("txt1").value = "bac";
    };
    </script>
    </head><body>
    <iframe name='main' src=b.htm ></iframe>
    </body></html>
    b.html<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>b</title>
    </head><body>
    <input type=text id="txt1">
    </body></html>