.: 发表评论 :. .: 最后更新 :. 再次转移Blog

.: 发表评论 :. .: 最后更新 :. 再次转移Blog 又是n久没有更新了 263.net == 恶心!!! 小玩了一把Thinlet 一个程序员的一生 酒桌偶感 我所期望的项目过程管理系统 随便说说2 人类SARS冠状病毒动物源性被证明 果子狸为主凶 很多公司往往会遇到这样两个问题 :: <<<说些无聊的话 | 首页 | 很多公司往往会遇到这样两个问题>>> 上传附件(类似gmail) gmail上传附件的时候是点击连接则直接出现文件选择对话框,选择文件之后文件名直接出现在相应位置,而不是采取一般的<input type=file>模式,至少表面不是。感觉挺有趣,打算搞一个玩玩,可惜gmail对源码做了处理,没法查看,后来网友顺其自然告知126.com的实现类似,于是跑去注册了一个,查看了一下源码,还好,没有做加密处理,ok,仔细看了一遍,js写的比较规范,也容易看懂,没费什么事,直接copy下来(呵呵,真是不好意思啊),简单修改了一下(原来使用的一个iframe处理的,改成就一个form,省事)。 其实这种上传模式还是采用的<input type=file>(唉,俺一开始还觉得挺神奇的),不过做了隐藏处理而已,具体情况看源码吧。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function debug(info) { //alert(info); } function getAttachFileId( Idx ) { return "attachfile" + Idx; } function getAttachInfoId( Idx ) { return "idAttachInfo" + Idx; } function getAttachOperId( Idx ) { return "idAttachOper" + Idx; } function getAttachBrId ( Idx ) { return "idAttachBr" + Idx; } var attaIdx = 0; var attaNameS = new Array(); var ExistAttaInfo = new Array(); function selectUploadFile() { var attaTagName = getAttachFileId( attaIdx ); var attachFileTag = "<input type=file style='display:none' name='" + attaTagName + "' id='" + attaTagName +"' onchange='syncinfo();'>"; var fileObj = document.getElementById( attaTagName );; if (fileObj == null) { debug("fileObj is null"); fileObj = document.createElement(attachFileTag); idAttaSpan.appendChild(fileObj); } fileObj.click(); return; } function setAttachInfo() { var objId = getAttachFileId( attaIdx ); var attaName = document.getElementById(objId).value; var attachFileId = getAttachFileId( attaIdx ); debug( 'setAttachInfo , attaIdx: ' + attaIdx + ' attaName: ' + attaName ); if (attaName == null || attaName == "" ) { alert('请选择一个文件'); deletenode( idAttaSpan, attachFileId); return false; } if ( checkFileExist( attaName ) ) { alert('此附件已粘贴, 如果在原有附件列表中并已删除,请取消删除;\n如果在新粘贴附件列表中,请先删除再粘贴。'); debug(' delete node ' + attachFileId ); deletenode( idAttaSpan, attachFileId); return false; } attaNameS[attaIdx] = attaName; attaName = getfilename(attaName); genAttachInfo( attaIdx, attaName ); attaIdx ++; return; } function genAttachInfo( Idx, theName ) { debug( ' gen Attach Info ' + Idx + ', the Name is ' + theName ); var attaInfoTag = "<span id='" + getAttachInfoId( Idx ) + "'>"; var attaOperTag = "<span id='" + getAttachOperId( Idx ) + "' onclick='deleteAttach(" + Idx + ");' style='color:blue;cursor:hand'>"; var attaBrTag = "<br id='" + getAttachBrId( Idx ) + "'>"; var aInfoElement = document.createElement(attaInfoTag); var aOperElement = document.createElement(attaOperTag); var brElement = document.createElement(attaBrTag); idAttaInfoArea.appendChild(aInfoElement); idAttaInfoArea.appendChild(aOperElement); idAttaInfoArea.appendChild(brElement); aOperElement.innerHTML = "&nbsp;&nbsp;<U>删除</U>"; var re = /\\\\/g; aInfoElement.innerText = theName.replace(re, '\\'); debug(idAttaInfoArea.innerHTML); return; } function deleteAttach( Idx ) { debug('delete ' + Idx + ' : ' + attaNameS[Idx]); attaNameS[Idx] = ""; deletenode( idAttaSpan, getAttachFileId( Idx )); deletenode( idAttaInfoArea, getAttachInfoId( Idx )); deletenode( idAttaInfoArea, getAttachOperId( Idx )); deletenode( idAttaInfoArea, getAttachBrId( Idx )); } function checkFileExist( attaName ) { debug( 'attaName = ' + attaName); if ( attaNameS.length <= 0 && ExistAttaInfo.length <= 0 ) return false; for (var i=0; i<attaNameS.length; i++) { var theName = attaNameS[i] ; if ( theName != null && theName != "" && theName == attaName ) { debug( " it's the same with attaNameS " + i ); return true; } } for (var i=0; i<ExistAttaInfo.length; i++) { var theName = ExistAttaInfo[i] ; if ( theName != null && theName != "" && theName == getfilename(attaName) ) { debug( " it's the same with ExistAttaInfo " + i ); return true; } } return false; } function getfilename( attaName ) { var s = attaName.lastIndexOf( '\\' ); return attaName.substr(s+1, attaName.length - s -1); } function deletenode( P, CID) { var attas = P.childNodes; var i; for (i=0; i<attas.length; i++ ) { var oChild = P.children(i); if (oChild.id == CID) { P.removeChild(oChild); } } } function syncinfo( ) { idAttachSyncer.click(); } //--> </SCRIPT> <BODY> <span name="idAttachSyncer" id="idAttachSyncer" height=0 onclick="setAttachInfo();"></span> <FORM name="uploadTest" METHOD=POST ACTION="" enctype="multipart/form-data"> <span id="idAttaInfoArea"></span> <INPUT TYPE="button" value="Click Here!" onClick="selectUploadFile()"> <span id="idAttaSpan"></span> </FORM> </BODY> </HTML> someok | 引用(trackback0) □ 评论 不能用来上传附件。请问高手:在这样<input type="file" name="files" style="diaplay:none">的情况下,如何上传附件(jsp) ◇ ppulong (

原始快照:web.archive.org