<form action="index.jsp" id="form1" name="form1" encType="multipart/form-data" method="post" target="hidden_frame" >   
  <input type="file" id="file" name="file" style="width:450" onpropertychange="form1.submit()">   
  <INPUT type="button" value="上传文件" onclick="file.click();"><span id="msg"></span>   
  <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>   
</form>  这是我把代码简化后的内容,这样就会出现js出现拒绝访问
而这样就不会<form action="index.jsp" id="form1" name="form1" encType="multipart/form-data" method="post" target="hidden_frame" >   
  <input type="file" id="file" name="file" style="width:450" onpropertychange="form1.submit()">   
    
  <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>   
</form>
那位大侠能说明一下,我需要上一种效果才能满足项目要求。

解决方案 »

  1.   

    表示完全没有你所说的哪种问题,是不是代码没有贴完整?还是我测试的浏览器版本不对?
    我用的是:IE9, chrome 13, firefox 12
      

  2.   

    onclick="file.click();
    会不会是这个问题啊
    IE8支持这种写法吗
      

  3.   

    用click方法,IE是不支持的,不用试了。换种思路:
    用隐藏的方法,把内容框隐藏掉:
    MVC Page:
    @using (Html.BeginForm("ImportUser", "UserManage", FormMethod.Post,
                                           new { enctype = "multipart/form-data", Id = "fileOnload" }))
                          {
                            <div class="classdetail_btn_box0101">
                            <!--浏览文件按钮-->
                                <div id="btnInport" class="classdetail_btn_box0102" style="padding:0;">
                            <div class="Gray_Content">
                              <span class="Gray_Font">@ViewBag.Import</span>
                                <!--地址框-->
                              <input type="file" id="importUserFileExcel" name="importUserFileExcel" size="1" onchange="SelectFileAndImport()" />
                            </div>
                                </div>
                            </div>
                          }
    CSS样式控制:
    <style type="text/css"> 
      .Gray_Content input{
     opacity:0;/*透明*/
     filter:alpha(opacity=0);
     cursor:pointer;
     margin:0px auto;
     margin-left:-83px;
     margin-left:-97px\9;
     +margin-left:-105px;
    }
    .Gray_Content{ cursor:hand;}</style>
      

  4.   

    漏了JS和后台:
    JS:
    function SelectFileAndImport(){        var filePath = $.trim($("#importUserFileExcel").val());
            if (filePath == "") {
                alert(userManage_filePath);
                return false;
            }        if (FileSize(filePath)) {
                return false;
            }        //document.getElementById("fileOnload").submit();
            $("#fileOnload").submit();
            //$("#tt").datagrid('reload');
        }
            function FileSize(files) {
                return false;
                var fso, f;
                fso = new ActiveXObject("Scripting.FileSystemObject");
                f = fso.GetFile(files);
                if (f.size > 10240 * 4) {
                    alert(userManage_fileSize);
                    return true;
                }            return false;
            }
    MVC 控制器:
    HttpFileCollectionBase httpFiles = Request.Files;
                HttpPostedFileBase file = httpFiles["importUserFileExcel"];
      

  5.   

    该问题(http://bbs.csdn.net/topics/300103140),同上面的问题一样,同样行不通,暂时只有上面这种解决方法了。
      

  6.   

    楼主可以研究下ajaxupload,jQuery的一个插件。原理是把fileupload控件做成透明的覆盖在button上,这样点击button的时候,实际上是在点击fileupload