问题描述
<%@ page language="java" pageEncoding="gb2312"%><%@ page import="java.util.Collection,java.util.Iterator"%><%@ page import="dy.web.beans.NewsClass" %><%@ page import="dy.web.mgr.NewsClassMgr" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSF 'addnews.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript" src="FCKeditor/fckeditor.js"></script><script type="text/javascript" src="FCKeditor/calendar/calendarShow.js"></script><script src="./javascript/jquery.js" type="text/javascript"></script><script src="./javascript/cookie.js" type="text/javascript"></script><script language="javascript"><!--function go(i){ var temp =i;fPopUpCalendarDlg(temp);}--></script><script language="javascript" type="text/javascript"> <!--function check_input(){var topictest=document.addnewsfrom.Topic.value;var contenttest=document.addnewsfrom.contest.value;if(topictest==''){alert('请输入新闻标题!');return false;}}--></script> </head><body><%!String attachfilename=""; %><%//后台传过来的参数attachfilename=(String)request.getAttribute("attachfilename");System.out.println("接受到了"+attachfilename);if(attachfilename==null){%><script type="text/javascript">alert("文件上传出错,请您重新上传!");</script><%}else{ %><script type="text/javascript">//要为输入框写入文件名alert("到这来了1");test('attachmentNum');var temgetcook = getCookie('attachmentNum');var affile=$('#attachmentFile'+temgetcook);var affilenametest =$('#attachmentNames'+temgetcook);alert("得到cookie的值是"+temgetcook);alert(affilenametest.val());//在这里获得不了有效值为什么?alert("填充框"+affile.val());alert("文件名测试二"+'<%=attachfilename%>');</script><%} %><script type="text/javascript">//上传附件function uploadAttachment(n) {var af = $('#attachmentFile'+n);var affilename =$('#attachmentNames'+n);//检查是否选择了文件if(af.val()=='') {alert('请选择要上传的文件');return;}alert(af.val());alert(affilename.val());//在这里获得没有问题//将file移动至上传表单$('#attachmentContent').empty();$('#attachmentContent').append(af);//复制一个file放至原处$('#afc'+n).append(af.clone().attr('value',''));//修改属性af.attr('id','');//其他表单$('#attachmentNum').val(n);$('#attachmentForm').submit();SetCookie ("attachmentNum",n);}</script><form id="attachmentForm" action="servlet/UploadServlet" method="post" enctype="multipart/form-data" target="attachment_iframe" style="display:none;width:0px;height:0px;"> <span id="attachmentContent"></span> <input type="hidden" id="attachmentNum" name="attachmentNum" size="30"/> </form> <iframe name="attachment_iframe" frameborder="0" border="0" style="display:none;width:0px;height:0px;"></iframe><form name="addnewsfrom" method="post" action="servlet/AddNewsServlet" onSubmit="return check_input()"><font size="2"><table width="100%" height="35" border="1" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--><tr><td width="40%" bordercolor="#FF0000" bgcolor="#FF3333" height="35" align="left"><font color="#ffffff"><b>当前位置:新闻管理 - 添加新闻</b></font><br></td><td width="40%" bordercolor="#FF0000" bgcolor="#FF3333" height="35" align=center><br></td><td width="20%" bordercolor="#FF0000" bgcolor="#FF3333" height="35" align="right"><input type="button" value="返回列表" onclick="window.location='servlet/NewsListServlet'"/><input type="hidden" name="cid" value="4"/></td></tr></table><table width="100%" height="5" border="0" cellpadding="0" cellspacing="0"><tr><td width="100%" height="5"></td></tr></table><table width="100%" height="" border="1" cellpadding="0" cellspacing="0"><!--DWLayoutTable--><tr id="topic"><td width="13%" height="30" align="right" bgcolor="#FFFF8E"><font color="#FF0000">*</font>标题:</td><td height="30" colspan="4"><input name="Topic" type="text" id="Topic" size="70" maxlength="255" /></td></tr><tr><td width="13%" height="" align="right" bgcolor="#FFFF8E">附件:</td><td height="30" colspan="4"><table id="attachTable" border="0"> <tr> <td align="center"><input type="button" onclick="addAttachLine();" value="增加"/></td> <td align="center">附件名称</td> <td align="center">附件地址</td> <td align="center">附件上传</td> </tr> </table><textarea id="attachTr" style="display:none"><tr id="attachTr{0}"><td align="center"><a onclick="$('#attachTr{0}').remove();" href="javascript:void(0);" class="pn-opt">删除</a></td><td align="center"><input type="text" id="attachmentNames{0}" name="attachmentNames"/></td><td align="center"><input type="text" id="attachmentPaths{0}" name="attachmentPaths"/></td><td align="center"><span id="afc{0}"><input type="file" id="attachmentFile{0}" name="attachmentFile" size="12" style="width:160px"/></span><input type="button" value="上传" onclick="uploadAttachment({0});"/><input type="hidden" id="attachmentFilenames{0}" name="attachmentFilenames"/></td></tr></textarea><script type="text/javascript">var attachIndex = 2;var attachTpl = $.format($("#attachTr").val());function addAttachLine() {$('#attachTable').append(attachTpl(attachIndex++));}</script></td></tr><tr><td width="100%" height="40" align="center" colspan="4" bgcolor="#FF3333"><input type="submit" value="提交" onclick="return confirm('是否确定提交?')"/><input type="reset" value="重置"/></td></tr></table></font></form></body></html>在上面代码中在未上传之前可以获得所要的值,但是在长传之后就是在后台上传处理之后就无法再次获得input的值!高手们请进啦! 问题补充:lizhi92574 写道
解决方案
因为你提交到iframe里面,iframe获取父面板元素,需要加window.parent;var affilenametest =window.parent.$('#attachmentNames'+temgetcook); alert(affilenametest.val());
解决方案二:
在添加完成之后你吧id值返回给iframe jsp页面,删除的时候通过iframe获取相应id,使用ajax提交删除。
解决方案三:
获取什么id?