2个iframe间传递参数及调用函数的问题!!! IframeID.contentWindow.document.hitrateform.hitnum.value=id; IframeID.contentWindow.document.subm(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不行,报"contentWindow.document.hitrateform.hitnum"为空或不是对象错误 function onhit(id) { ifrm1.document.hitrateform.hitnum.value=id; ifrm1.subm();} 先搞清楚,你点击的这个链接与hitrate.jsp是什么关系? 你的那个写法是:IframeID.Document.hitrateform.hitnum.value=id; 链接在主页面还是在嵌入的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(); } 链接是在主页面上,按楼上的方法,报contentWindow.document.getElementById()为空或不是对象错误 IframeID.contentWindow.document.getElementsByName("hitnum")[0].value <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> 还是document.hitrateform.hitnum为空或不是对象错误,我也换了好几种写法了,都是差不多的错误,不知道怎么回事 经测试以上代码没问题请查看是否存在ID为ifrm1的IFRAME请查看IFRAME内是否有ID为hitnum的INPUT请查看IFRAME内是否有subm的方法另外请查看onhit方式是否是在IFAME内容加载完后执行 应该是你的IFAME还未加载完后你就执行了以上代码IFAME内内容未加载完毕当然不存在hitnum控件和subm方法了 改成下面这样试试。<script language="javascript">function onhit(id) { ifrm1.document.getElementById("hitnum").value=id;ifrm1.document.hitrateform.submit(); } </script> 肯定都有,下面都是我拷贝出来的:<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内容加载完后了 郁闷,其实我最开始的写法就是:ifrm1.hitrateform.hitnum.value=id; ifrm1.subm(); 是可以的,现在不知道怎么了,咋写都不对了 大家给我提供的方法我都测试了,都是 '为空或不是对象错误'只是内容有的是:document.hitrateform.hitnum或document.getElementById 我测试的代码如下: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>测试通过的 楼主,调用onhit方法的时候是什么时候调用的?还是怀疑IFRAME未加载完造成的试试在onhit方法内写alert(IframeID)alert(IframeID.contentWindow)alert(IframeID.contentWindow==window)alert(IframeID.contentWindow.document.body.innerHTML) 找个脚本调试工具 例如 vs2005 vs2008 实时查看dom对象 比楼上alert好一些 链接在主页面还是在嵌入的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(); } 惭愧!大家给我的方法都好用,我最初的用法也没问题的,是hitrate.jsp中包含的一个文件出问题了影响的,十分感谢大家!再请帮我看看这个新问题:http://topic.csdn.net/u/20080703/09/a7e5646d-fc70-49e4-8260-0ead2e285324.html谢谢! kindeditor-4.1.5 如何修改百度地图默认地址 关于window.open的问题 ext 布局左边点击,右边显示不了 为什么不能给onChange事件添加函数???? javascript引用框架问题 用js代码怎么才能插入一个flash呢? 如何在页面中控制背景图片?请教 送分!form.select.length和form.select.options.length是一样的吗? 想各位帮我复制一篇文章谢谢 使<div>显示在<select>上面? 关于一个字符串截取问题 (求助)一种鼠标触发的效果
{
ifrm1.document.hitrateform.hitnum.value=id;
ifrm1.subm();
}
IframeID.Document.hitrateform.hitnum.value=id;
主页面的话如下:
页面上包含一个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();
}
contentWindow.document.getElementById()为空或不是对象错误
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>
以上代码没问题
请查看是否存在ID为ifrm1的IFRAME
请查看IFRAME内是否有ID为hitnum的INPUT
请查看IFRAME内是否有subm的方法另外请查看onhit方式是否是在IFAME内容加载完后执行
IFAME内内容未加载完毕当然不存在hitnum控件和subm方法了
<script language="javascript">
function onhit(id)
{
ifrm1.document.getElementById("hitnum").value=id;
ifrm1.document.hitrateform.submit();
}
</script>
<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内容加载完后了
ifrm1.hitrateform.hitnum.value=id;
ifrm1.subm();
是可以的,现在不知道怎么了,咋写都不对了
只是内容有的是:
document.hitrateform.hitnum
或
document.getElementById
<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>测试通过的
调用onhit方法的时候是什么时候调用的?
还是怀疑IFRAME未加载完造成的
试试在onhit方法内写
alert(IframeID)
alert(IframeID.contentWindow)
alert(IframeID.contentWindow==window)
alert(IframeID.contentWindow.document.body.innerHTML)
主页面的话如下:
页面上包含一个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();
}
再请帮我看看这个新问题:
http://topic.csdn.net/u/20080703/09/a7e5646d-fc70-49e4-8260-0ead2e285324.html
谢谢!