用javascript打开文件对话框

时间:2013-10-31 16:52:36

标签: javascript jquery file-upload click double-click

我尝试在javascript中打开文件对话框。我尝试了下一个代码:

 <script type="text/javascript">

        $(document).ready(function () {
            $("#lblupload").click(function () {

                $("#upload").trigger('click');
            });

            $("#upload").change(function () {
                $("#div").css("display", "block");
            });
        });


    </script>

  <asp:Label ID="lblupload" runat="server" ClientIDMode="Static" >UPLOAD</asp:Label>

        <asp:FileUpload ID="upload" runat="server" />



        <div id="div" style="display:none;">
           Are you sure ... ?
               <asp:Button ID="btn_upload" runat="server" OnClick="btn_upload_Click" Text="yes" />

        </div>

除IE以外的所有浏览器都很好用。 在IE中,单击按钮* btn_upload *不能仅双击。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您在日志中看到了哪些错误?我刚刚尝试了这个例子,它可以直接回到IE 7:

<asp:Label ID="lblupload" runat="server" ClientIDMode="Static" >UPLOAD</asp:Label>

<asp:FileUpload ID="upload" runat="server" />    

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>
    $(function () {
        $('#lblupload').on('click', function () {
            $('#upload').trigger('click');
            return false;
        });
    });
</script>