<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>
那位大侠能说明一下,我需要上一种效果才能满足项目要求。
<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>
那位大侠能说明一下,我需要上一种效果才能满足项目要求。
我用的是:IE9, chrome 13, firefox 12
会不会是这个问题啊
IE8支持这种写法吗
用隐藏的方法,把内容框隐藏掉:
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>
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"];