iframe上传文件

功能:父页面点击提交按钮后,iframe上传文件,文件上传成功则自动提交父页面数据,上传失败在iframe中显示出错信息。

[size=large][b]父页面[/b][/size]

<s:form action="saveApply" namespace="/variation" theme="simple" enctype="multipart/form-data" method="post">
<iframe src="variation/toUpload.action?projectId=${projectId}" name="uploadFile" frameborder="0" scrolling="no" width="100%"></iframe>
<input type="button" class ="input" value="<s:text name="i18n_Save" />" onclick="toUpload()" />
</s:form>


[size=large][b]父页面js[/b][/size]
function toUpload(){
window.frames["uploadFile"].uploadFile();
}

function toSubmit(){
document.forms[0].submit();
}

[size=large][b]子页面[/b][/size]

<body onload="submitForm()">
<s:form action="saveFile" namespace="/variation" theme="simple" enctype="multipart/form-data" method="post">
<table class="table_add_issue" cellspacing="0" cellpadding="0">
<tr style="height:31px">
<td class="wdaddname"><s:text name="i18n_UploadVariation"></s:text></td>
<td class="wdaddvalue">
<s:file name="uploadFile" />
<a href="variation/download.action"><s:text name="i18n_DownloadFileTemplate"></s:text></a>
</td>
</tr>
</table>
<s:hidden name="projectId" value="%{projectId}" />
<s:hidden name="fileFlag" value="%{fileFlag}" />
<div id="inputtip">
<s:property value="tip" />
<s:fielderror theme="simple" />
<s:actionerror theme="simple" />
</div>
</s:form>
</body>


[b][size=large]子页面js[/size][/b]

function uploadFile(){
document.forms[0].submit();
}

function submitForm(){
var fileFlag = document.getElementsByName("fileFlag")[0].value;
if(fileFlag==0){
}else if( fileFlag==1){
parent.toSubmit();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值