IframeID.contentWindow.document.hitrateform.hitnum.value=id; 
IframeID.contentWindow.document.subm(); 

解决方案 »

  1.   

    不行,报"contentWindow.document.hitrateform.hitnum"为空或不是对象错误
      

  2.   

    function onhit(id) 

    ifrm1.document.hitrateform.hitnum.value=id; 
    ifrm1.subm();
      

  3.   

    先搞清楚,你点击的这个链接与hitrate.jsp是什么关系?
      

  4.   

    你的那个写法是:
    IframeID.Document.hitrateform.hitnum.value=id; 
      

  5.   

    链接在主页面还是在嵌入的Iframe的hitrate.jsp内?
    主页面的话如下:
    页面上包含一个iframe : 
    <iframe id=ifrm1 name=ifrm1  src="hitrate.jsp"  style="display:none"> </iframe>  hitrate.jsp中有一个form ,一个函数 和一个隐藏域 : 
    <form name=hitrateform  method="post" action="hitrate.jsp"> 
    function subm() 

    ... 

    <input id="hitnum" type="hidden" name="hitnum" value=""> 我想在此页面上点击一个链接后对hitrate.jsp中的hitnum付值,并调用subm函数,我写了如下的代码,但不对,请问应该怎么实现? 
    function onhit(id) 

    var IframeID=document.getElementById("ifrm1"); 
    IframeID.contentWindow.document.getElementById("hitnum").value=id; 
    IframeID.contentWindow.subm(); 

      

  6.   

    链接是在主页面上,按楼上的方法,报
    contentWindow.document.getElementById()为空或不是对象错误 
      

  7.   

    IframeID.contentWindow.document.getElementsByName("hitnum")[0].value
      

  8.   

    <script>
    function onhit(id){ 
    //window.frames['ifrm1'].document.getElementById('hitnum').value=id; 
    //window.frames['ifrm1'].subm(); 
    var IframeID=window.frames['ifrm1']; 
    IframeID.document.hitrateform.hitnum.value=id; 
    IframeID.subm(); 

    </script>
      

  9.   

    还是document.hitrateform.hitnum为空或不是对象错误,我也换了好几种写法了,都是差不多的错误,不知道怎么回事
      

  10.   

    经测试
    以上代码没问题
    请查看是否存在ID为ifrm1的IFRAME
    请查看IFRAME内是否有ID为hitnum的INPUT
    请查看IFRAME内是否有subm的方法另外请查看onhit方式是否是在IFAME内容加载完后执行
      

  11.   

    应该是你的IFAME还未加载完后你就执行了以上代码
    IFAME内内容未加载完毕当然不存在hitnum控件和subm方法了
      

  12.   

    改成下面这样试试。
    <script language="javascript">
    function onhit(id) 
    {   
    ifrm1.document.getElementById("hitnum").value=id;
    ifrm1.document.hitrateform.submit(); 

    </script>
      

  13.   

    肯定都有,下面都是我拷贝出来的:
    <iframe id=ifrm1 name=ifrm1  src="hitrate.jsp"  style="display:none"></iframe>  <input type="hidden" name="hitnum" value=""><script language="javascript">
    function subm()
    {
    document.hitrateform.submit();
    }
    </script>onhit也是主页面的一个连接,肯定IFAME内容加载完后了
      

  14.   

    郁闷,其实我最开始的写法就是:
    ifrm1.hitrateform.hitnum.value=id;
    ifrm1.subm(); 
    是可以的,现在不知道怎么了,咋写都不对了
      

  15.   

    大家给我提供的方法我都测试了,都是 '为空或不是对象错误'
    只是内容有的是:
    document.hitrateform.hitnum

    document.getElementById
      

  16.   

    我测试的代码如下:test.jsp
    <script>
    function onhit(id){ 
    //window.frames['ifrm1'].document.getElementById('hitnum').value=id; 
    //window.frames['ifrm1'].subm(); 
    var IframeID=window.frames['ifrm1']; 
    IframeID.document.hitrateform.hitnum.value=id; 
    IframeID.subm(); 

    </script>
    <div>
    <a href="#" onClick="onhit(1)">aaaa</a>
    <iframe src="1.jsp" id="ifrm1" name="ifrm1"></iframe>1.jsp<form name="hitrateform"  method="post" action="hitrate.jsp"> 
    <script language="javascript">
    function subm() 

    alert(document.hitrateform.hitnum.value)

    </script>
    <input type="hidden" name="hitnum" id="hitnum" value=""> 
    </form>测试通过的
      

  17.   

    楼主,
    调用onhit方法的时候是什么时候调用的?
    还是怀疑IFRAME未加载完造成的
    试试在onhit方法内写
    alert(IframeID)
    alert(IframeID.contentWindow)
    alert(IframeID.contentWindow==window)
    alert(IframeID.contentWindow.document.body.innerHTML)
      

  18.   

    找个脚本调试工具 例如 vs2005 vs2008  实时查看dom对象  比楼上alert好一些 
      

  19.   

    链接在主页面还是在嵌入的Iframe的hitrate.jsp内? 
    主页面的话如下: 
    页面上包含一个iframe : 
    <iframe id=ifrm1 name=ifrm1  src="hitrate.jsp"  style="display:none"> </iframe>  hitrate.jsp中有一个form ,一个函数 和一个隐藏域 : 
    <form name=hitrateform  method="post" action="hitrate.jsp"> 
    function subm() 

    ... 

    <input id="hitnum" type="hidden" name="hitnum" value=""> 我想在此页面上点击一个链接后对hitrate.jsp中的hitnum付值,并调用subm函数,我写了如下的代码,但不对,请问应该怎么实现? 
    function onhit(id) 

    var IframeID=document.getElementById("ifrm1"); 
    IframeID.contentWindow.document.getElementById("hitnum").value=id; 
    IframeID.contentWindow.subm(); 

      

  20.   

    惭愧!大家给我的方法都好用,我最初的用法也没问题的,是hitrate.jsp中包含的一个文件出问题了影响的,十分感谢大家!
    再请帮我看看这个新问题:
    http://topic.csdn.net/u/20080703/09/a7e5646d-fc70-49e4-8260-0ead2e285324.html
    谢谢!