在ASP中添加文件上载的点击事件

时间:2014-02-14 12:49:56

标签: jquery asp.net file-upload

我有一个应用程序,每次我在asp中使用文件上传浏览时都会预览图像。

这是我的代码:

ASPX:

<asp:Panel ID="stage" runat="server" cssClass="containment-wrapper" style="border:1px solid #000000;">
         <asp:Image ID="imgBrowse" runat="server" Height="375px" Width="640px" ImageUrl="Image/ClickHere.png" style="cursor:pointer"/>
         <asp:FileUpload ID="FileUpload_IE" runat="server" style="display:none;" />
         <asp:Button ID="btn_UploadHandler" runat="server" Text="Button" OnClick="btn_UploadHandler_Click" style="display:none;"/>
</asp:Panel>

JS:

$("#stage").click(function () {
    if (navigator.appName == "Microsoft Internet Explorer") {
        $('#FileUpload_IE')[0].click();       
    }
});


$("#FileUpload_IE").on("change", function () {
        $("#btn_UploadHandler").click();
});

当我在IE8中运行时,此代码在$("#btn_UploadHandler").click();中出错。错误发生在jquery-1.10.2.js中。

Exception was thrown at line 5039, column 7 in http://localhost:25386/Script/jquery-1.10.2.js:

 // Prevent re-triggering of the same event, since we already bubbled it above
jQuery.event.triggered = type;
   try {

      elem[ type ]();

   } catch ( e ) {
           // IE<9 dies on focus/blur to hidden element (#1486,#12518)
          // only reproducible on winXP IE8 native, not IE9 in IE8 mode
   }
jQuery.event.triggered = undefined;

它在elem[ type ]();停止。

任何替代方法如何实现这一目标?

0 个答案:

没有答案