本文介绍了如何从文件上传器中侦听取消事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 //事情如下: //在Chrome中:首先我单击浏览并选择一个文件,然后再次单击浏览然后再按 / / cancel,文件上传器清除。 (但这不会发生在IE中) //为此,我需要知道,在文件上传中按下了哪个按钮(确定/取消) //对话框 //这是我的JS < script type = text / javascript> function clear(){ if ($ .browser .msie){ // 清除文件上传者 var who = document .getElementsByName( ' <%= fileID.UniqueID%>')[ 0 ]; who.value = ; var who2 = who.cloneNode( false ); who2.onchange = who.onchange; who.parentNode.replaceChild(who2,who); // ========= } } < / script> // Html < div id = upload-area > < asp:FileUpload ID = fileID runat = 服务器 宽度 = 427px onclick = clear() / > < / div > 解决方案 .browser.msie){ / / 清除文件上传者 var who = document .getElementsByName(' <%= fileID.UniqueID %>')[ 0 ]; who.value = ; var who2 = who.cloneNode( false ); who2.onchange = who.onchange; who.parentNode.replaceChild(who2,who); // ========= } } < / script> // Html < div id = upload-area > < asp:FileUpload ID = fileID runat = 服务器 宽度 = 427px onclick = clear() / > < / div > 嗨Kingshuk, 引用:我需要知道,在文件上传中按下了哪个按钮(确定/取消)你不能直接这样做。因为文件对话框没有暴露给浏览器。 我搜索了这个并得到了一个不同的方法。这不是直接的,但通过这种方式你可以得到你的解决方案。 链接 - http://jsfiddle.net/Shiboe/yuK3r/6/ [ ^ ] 我也得到了这个,但它不是我需要的方式..//The thing is like :// In chrome : First I click browse and select a file, then again, if I click browse and then// cancel, the file uploader get cleared. (but that doesn't happen in IE)// for that, I need to know, which button (OK / Cancel) is being pressed in the file upload// dialog box//Here's my JS<script type="text/javascript"> function clear() { if ($.browser.msie) { //To clear the file uploader var who = document.getElementsByName('<%= fileID.UniqueID %>')[0]; who.value = ""; var who2 = who.cloneNode(false); who2.onchange = who.onchange; who.parentNode.replaceChild(who2, who); //========= } }</script>// Html<div id="upload-area"> <asp:FileUpload ID="fileID" runat="server" Width="427px" onclick="clear()"/> </div> 解决方案 .browser.msie) { //To clear the file uploader var who = document.getElementsByName('<%= fileID.UniqueID %>')[0]; who.value = ""; var who2 = who.cloneNode(false); who2.onchange = who.onchange; who.parentNode.replaceChild(who2, who); //========= } }</script>// Html<div id="upload-area"> <asp:FileUpload ID="fileID" runat="server" Width="427px" onclick="clear()"/> </div>Hi Kingshuk,Quote: I need to know, which button (OK / Cancel) is being pressed in the file uploadYou can't do it directly. As file dialog is not exposed to the browser.I have searched for this and got a different approach to it. Here it is not direct, but in this way you can get your solution.Link - http://jsfiddle.net/Shiboe/yuK3r/6/[^]I also got this, but its not the way I need.. 这篇关于如何从文件上传器中侦听取消事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 02:35