我有一个页面,将上传控件隐藏在一个FORM里,然后通过一个图片调用上传控件,选择图片后,利用JAVASCRIPT POST 这个FORM到一个IFRAME里,POST的那个页面里有一个调用父级的脚本,用来显示两个DIV,但是怎么也改变不了父页面的DIV样式,但是值是可以获取到的,代码如下:index.htm:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>无标题文档</title>
<style type="text/css">
BODY {
font-family:"宋体", "Lucida Grande", Verdana, Lucida, Arial, Helvetica, sans-serif;
font-size:12px;
}
input.file {
width: 200px;
padding:1px 15px 3px 15px;
 *padding:4px 6px 0 6px;
background-color:#FFFFFF
}
#noteinput .note_type_photo {
position: absolute;
top:0px;
left:0px;
padding:4px 0 0 5px;
}
#noteinput .note_type_photo_con {
padding:2px 0 0 17px;
}
#noteinput .note_type_photo_con {
background:url(photo.gif) no-repeat 0% 0%;
}
#noteinput .type_file {
position:absolute;
top:3px;
left:-10px;
opacity:0;
filter:alpha(opacity=0);
width:0px;
cursor: pointer;
}
#noteImgUploading {
margin:5px 0 0 5px;
display:none;
}
#noteImgPreview {
margin:5px 0 0 5px;
padding:3px 0 0 20px;
display:none;
}
#noteImgPreview{
background:url(photo.gif) no-repeat;
}
#noteImgPreview .img_preview_close {
cursor: pointer;
}
</style></head>
<body>
<div id="noteTypeSelect">
  <div id="noteinput">
    <div id="type_photo" class="note_type_photo">
      <div class="note_type_photo_con">图片</div>
      <form name="imgform" id="imgform" method="post" action="" enctype="multipart/form-data" target="submitFrame" onsubmit="return false;">
        <input class="type_file" type="file" size="1" id="notePhoto" name="notePhoto" onkeydown="return false" onchange="aa()"/>
      </form>
    </div>
    <div id="noteImgUploading"> <img src="link_wait.gif"/> 请等待图片上传... </div>
    <div id="noteImgPreview"> <span id="noteImgFileName"></span> <img class="img_preview_close" onclick="del()" src="delete.gif" title="删除" alt="删除"/> </div>
    <div style="display:none">
      <input type="text" id="noteFilePath" name="noteFilePath" value="" />
    </div>
  </div>
</div><iframe id="submitFrame" name="submitFrame" style="display:none"></iframe>
<script language="javascript">
function aa(){

document.getElementById("noteImgUploading").style.display = "none";
document.getElementById("noteImgPreview").style.display = "none";


var a = document.getElementById("notePhoto");
if(a.value !="")
{
document.getElementById("noteTypeSelect").style.display = "none";
document.getElementById("noteImgUploading").style.display = "block";

document.getElementById("imgform").setAttribute("action","p.asp"); //FORM提交到这个页面
document.getElementById("imgform").submit();
}
}function bb(errorCode,noteFilePath)
{
if(errorCode == "0" && noteFilePath != ""){
var linkPathName = noteFilePath.substr(noteFilePath.lastIndexOf('/')+1);

document.getElementById("noteFilePath").value = noteFilePath;
document.getElementById("noteImgFileName").text = linkPathName; //alert这里都可以获取到值
document.getElementById("noteImgUploading").style.display = "none"; //这里就改变不了样式
document.getElementById("noteImgPreview").style.display = "block";
}
}
</script>
</body>
</html>
p.asp:
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
<script type="text/javascript">
function close(){
window.parent.bb('0','http://www.google.cn/intl/zh-CN/images/logo_cn.gif');
                           //这里可以调用到父页面的BB函数,但是样式死活修改不了,不知道为什么。
}
</script>
 
  </head>
  
  <body onLoad="close();">
  </body>
</html>

解决方案 »

  1.   

    那你就在 bb 函数里,修改parent frame 的样式好了。
      

  2.   


    我是想在POST到iframe 以后,用子页面修改父页面的样式,也就是BB函数所在页面的样式。
      

  3.   


    是同一个域名,都是在本机localhost下测试的。就不行,子页面能调用到父级页面的BB函数,但是修改DIV显示样式就不行,style.display="block"就没反应。
      

  4.   

    拼写错误吧。
    styles.display
      

  5.   

    代码问题,是你把“noteTypeSelect”先隐藏起来了,后头又不把它显示出来