jsp中利用js向父窗体表单传值并提交 30
父窗体有个表单:<formaction="index.jsp"name="aa"><inputtype="hidden"name="userid"/><inputtype...
父窗体有个表单:
<form action="index.jsp" name="aa">
<input type="hidden" name="userid"/>
<input type="hidden" name="a"/>
</form>
通过:<iframe width="100%" height="100%" frameborder="0" name="mainFrame" >调用子窗体
我想从子窗体向父窗体传值并提交:
<script language="javascript">
window.parent.document.aa.userid.value="<%=userid%>";
window.parent.document.aa.a.value="<%=a%>";
window.parent.document.aa.submit();
</script>
为什么没效果
还是不行啊 展开
<form action="index.jsp" name="aa">
<input type="hidden" name="userid"/>
<input type="hidden" name="a"/>
</form>
通过:<iframe width="100%" height="100%" frameborder="0" name="mainFrame" >调用子窗体
我想从子窗体向父窗体传值并提交:
<script language="javascript">
window.parent.document.aa.userid.value="<%=userid%>";
window.parent.document.aa.a.value="<%=a%>";
window.parent.document.aa.submit();
</script>
为什么没效果
还是不行啊 展开
2个回答
展开全部
parent.html
-----------
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title></title>
</head>
<body>
<form action="index.jsp" method="post" name="aa">
<input type="hidden" name="userid" id="userid"/>
</form>
<iframe src="child.html" width="100%" height="200px"></iframe>
</body>
</html>
child.html
-----------
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title></title>
<script type="text/javascript">
function submit(){
if(parent){
var doc = parent.document;
doc.forms["aa"].submit();
}
}
</script>
</head>
<body>
<input type="button" onclick="submit()" value="提交" />
</body>
</html>
如果乱码把utf8改成gb2312
-----------
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title></title>
</head>
<body>
<form action="index.jsp" method="post" name="aa">
<input type="hidden" name="userid" id="userid"/>
</form>
<iframe src="child.html" width="100%" height="200px"></iframe>
</body>
</html>
child.html
-----------
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title></title>
<script type="text/javascript">
function submit(){
if(parent){
var doc = parent.document;
doc.forms["aa"].submit();
}
}
</script>
</head>
<body>
<input type="button" onclick="submit()" value="提交" />
</body>
</html>
如果乱码把utf8改成gb2312
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询