小弟现在做一个网页,其中html是别人写的,现在我把html嵌入我的网页中,用iframe.但是问题来了,我无法获取 iframe中的image控件的单击事件。
代码如下:<form id= "loginform" action="home.html" onsubmit="return login_form(this);" method="get">                            
    <table width="450" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td width="164" rowspan="2" align="center" valign="middle">
        <Input name="Submit" type="image" value="Submit" src="images/login_33.jpg" width="119" height="59" border="0"> 
        </td>
      </tr>
</table>父页面的JS
document.frames("iframe1").document.getElementById("submit").onclick =  test();这样行不通的,请教各位该怎么弄呀?

解决方案 »

  1.   

    document.frames["iframe1"].document.getElementById("submit").onclick = test;
      

  2.   

    getElementById("submit"),
    好像没有这个id吧,你在submit里定义一个相应id
    <input id=”submit" type="image" value="Submit" src="images/login_33.jpg" width="119" height="59" border="0">  
    这个试一试;
      

  3.   


    不行哦
    消息: 'document.frames.iframe2.document.getElementById(...)' 为空或不是对象
      

  4.   

    document.frames["iframe1"].document.getElementsByName("Submit")[0].onclick = test;
    这样试试~·
      

  5.   

    可以了。谢谢了。马上给分。
    再请教个问题。
    为什么我写的ajax没有用呢。可以指点一下吗?
    function test1()
            {
                
                var uname;
                var upwd;
                uname = document.frames("iframe2").document.getElementById("email").value;
                upwd = document.frames("iframe2").document.getElementById("password").value;
                alert("a");
                try 
                { 
                    alert("b");
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                } 
                catch (e) 
                { 
                    alert("c");
                    try 
                    { 
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
                    } 
                    catch (e) 
                    {  
                        try 
                        { 
                            xmlhttp=new XMLHttpRequest(); 
                        } 
                        catch (e) 
                        { 
                        } 
                    } 
                 }  
                var url =  "/login_lod.aspx?name="+uname+"&pwd="+upwd;
                alert(url);
                xmlHttp.open("GET",url, true);              
                xmlhttp.onreadystatechange=function() 
                  { 
                    alert("e");
                    if(4==xmlhttp.readyState) 
                    { 
                        if(200==xmlhttp.status) 
                        { 
                            if (xmlhttp.responseText=="yes") 
                            {  
                               alert("1"); 
                            } 
                            else 
                            { 
                                alert("2"); 
                                alert("你输入的用户名或密码不正确,请重新输入!");
                               
                            }  
                        } 
                        else 
                        { 
                          alert("3");
                        } 
    //                    var ch=document.getElementById("check1"); 
    //                  ch.innerHTML=msg;  
                    } 
                  } 
               
            }我测试了一下。只弹出到URL,没有进到onreadystatechange的function里。这是怎么回事呀?
      

  6.   

    function test1()
            {
                
                var uname;
                var upwd;
                uname = document.frames("iframe2").document.getElementById("email").value;
                upwd = document.frames("iframe2").document.getElementById("password").value;
                alert("a");
                try 
                { 
                    alert("b");
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                } 
                catch (e) 
                { 
                    alert("c");
                    try 
                    { 
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
                    } 
                    catch (e) 
                    {  
                        try 
                        { 
                            xmlhttp=new XMLHttpRequest(); 
                        } 
                        catch (e) 
                        { 
                        } 
                    } 
                 }  
                var url =  "http:/localhost/login_ajax.aspx?name="+uname+"&pwd="+upwd;
                alert(url);
                xmlHttp.open("GET",url, true);              
                xmlhttp.onreadystatechange=function() 
                  { 
                    alert("e");
                    if(4==xmlhttp.readyState) 
                    { 
                        if(200==xmlhttp.status) 
                        { 
                            if (xmlhttp.responseText=="yes") 
                            {  
                               alert("1"); 
                            } 
                            else 
                            { 
                                alert("2"); 
                                alert("你输入的用户名或密码不正确,请重新输入!");
                               
                            }  
                        } 
                        else 
                        { 
                          alert("3");
                        } 
    //                    var ch=document.getElementById("check1"); 
    //                  ch.innerHTML=msg;  
                    } 
                  } 
               
            }
    只弹出到alert(url);这里。后面就没有继续下去了。