情况是这样的:
我现在要做一个文件上传的功能,
<form id="form2" method="post" enctype="multipart/form-data"
action="poList.do?method=readExcel">
<input id="file1" type="file" name="file" />
<input type="submit" name="btnOrder" />
</form>
这样的代码做文件上传是可以的.
但是我现在需要用把上面的控件都隐藏起来,用一个button来触发文件选择和提交这两个功能.
下面是我的代码:
1:隐藏了这些控件
<div style="display: none">
<form id="form2" method="post" enctype="multipart/form-data"
action="poList.do?method=readExcel">
<input id="file1" type="file" name="file" style="display: none;"/>
<input type="submit" name="btnOrder" />
</form>
</div>
2:添加了一个button按钮来触发事件
<a onClick="readExcel();" id="5"><span ><img
align="left" src="images/toolbar/import.gif" />Import</span> </a>
3:下面是js代码
function readExcel(){
document.all.file1.onclick;
document.all.btnOrder.click();
} 结果就是提示js错误:拒绝访问.
我也查了很多资料,说是把file控件隐藏就会出现拒绝访问的情况.
那位帮我看看?
我现在要做一个文件上传的功能,
<form id="form2" method="post" enctype="multipart/form-data"
action="poList.do?method=readExcel">
<input id="file1" type="file" name="file" />
<input type="submit" name="btnOrder" />
</form>
这样的代码做文件上传是可以的.
但是我现在需要用把上面的控件都隐藏起来,用一个button来触发文件选择和提交这两个功能.
下面是我的代码:
1:隐藏了这些控件
<div style="display: none">
<form id="form2" method="post" enctype="multipart/form-data"
action="poList.do?method=readExcel">
<input id="file1" type="file" name="file" style="display: none;"/>
<input type="submit" name="btnOrder" />
</form>
</div>
2:添加了一个button按钮来触发事件
<a onClick="readExcel();" id="5"><span ><img
align="left" src="images/toolbar/import.gif" />Import</span> </a>
3:下面是js代码
function readExcel(){
document.all.file1.onclick;
document.all.btnOrder.click();
} 结果就是提示js错误:拒绝访问.
我也查了很多资料,说是把file控件隐藏就会出现拒绝访问的情况.
那位帮我看看?
<input type="hidden" name="iframeName" />
<font size="-1">上传文件:</font> <input type="file" size="25" name="upfile" id="ff" onchange="subf.click();"/>
<input type="submit" value="上传" id="subf" style="display:none">
</form>
z\总体实现就是把上传那个组建hidden 然后一个按钮替代他提交 即onClick="subf.click();"
<form action="" name="" method="post">
<input type="hidden" name="iframeName" />
<font size="-1">上传文件:</font> <input type="file" type="display:none" size="25" name="upfile" id="ff" />
<input type="button" value="上传" onclick="upfile.click()">
</form>
<input type="file" id="file11" name="file" onchange="input1.value=this.value" style="width:1px;position:absolute;left:747px;filter:alpha(opacity=0);">[[/code]
4楼你赋值给textbox我文件的地址是对的,但是文件本身怎么提交到后台呢,现在我也是这样做,但是提交的VALUE都只是文件的地址,而不是我真正要的文件流.
现在的问题是这个form只有实现了enctype="multipart/form-data" 才能提交文件流,所以我的<input type="file">必须放到form里
但是把它放到form里并且隐藏它的话就会出现"拒绝访问"
而我不放到里面的话就不能提交文件流到后台/.
期待高手解答/
出现选择文件对话框
选中之后直接提交
不知道是不是这个意思
<form action="/lhkjywgl/Upload.do " name="UploadForm" enctype="multipart/form-data" method="post" onsubmit="return chickfile();">
<input size="24" type="hidden" name="comment"/>
<input type="hidden" name="iframeName" />
<font size="-1">上传文件:</font> <input type="file" size="25" name="upfile" id="ff" onchange="subf.click();"/>
<input type="submit" value="上传" id="subf" style="display:none">
</form>
<input type="file" size="25" name="upfile" id="ff" onchange="subf.click();"/>这个东西也隐藏才行
类似这种也许可以解决问题.........
1、首先把input=file做成透明来隐藏
2、要明确一点:用其它按钮的click时间来触发input=file时间是不可能的,一定会拒绝访问
3、input=file必须被主动触发,而不是由Js函数来被动click
4、唯一的办法:点击你的submit按钮,而实际上点的是input=file的按钮
5、所以要用Js控制透明之后的input=file绝对位置
6、曾经的一个做法是,当鼠标进入submit按钮区域,就把input=file动态的移动到submit的位置,相当于有个透明层位于submit上方
7、此时点击submit首先影响的是把它给挡住的input=file,然后再发生自己的点击事件,这样就属于主动点击input=file的按钮
8、需要注意的是隐藏和坐标计算,包括焦点处理都得要妥善完成,你可以先用半透明调整好位置