Javascript Jquery:关于使用iframe将文件上载到服务器

Javascript Jquery:关于使用iframe将文件上载到服务器,javascript,jquery,iframe,file-upload,Javascript,Jquery,Iframe,File Upload,在下面的代码中,iframe用于将文件上载到服务器。查看代码并告诉我何时触发iframe加载事件 <script type="text/javascript"> $(document).ready(function () { $("#formsubmit").click(function () { var iframe = $('<iframe name="postiframe" id="postiframe" style="

在下面的代码中,iframe用于将文件上载到服务器。查看代码并告诉我何时触发iframe加载事件

<script type="text/javascript">
    $(document).ready(function () {

        $("#formsubmit").click(function () {

            var iframe = $('<iframe name="postiframe" id="postiframe" style="display: none"></iframe>');

            $("body").append(iframe);

            var form = $('#theuploadform');
            form.attr("action", "/upload.aspx");
            form.attr("method", "post");

            form.attr("encoding", "multipart/form-data");
            form.attr("enctype", "multipart/form-data");

            form.attr("target", "postiframe");
            form.attr("file", $('#userfile').val());
            form.submit();

            $("#postiframe").load(function () {
                iframeContents = this.contentWindow.document.body.innerHTML;
                $("#textarea").html(iframeContents);
            });

            return false;

        });

    });

</script>
参见代码 这一行正在做什么
iframeContents=this.contentWindow.document.body.innerHTML

为什么需要以下代码。 如果我们删除了上面的代码,那么当我们试图调用
iframe
…的加载事件时,表单也将被提交

请详细讨论,以便正确理解。谢谢


谢谢

除非您有非常具体的原因,否则您应该使用类似“我只是想理解代码”的内容。
$("#postiframe").load(function () {
                iframeContents = this.contentWindow.document.body.innerHTML;
                $("#textarea").html(iframeContents);
            });
$("#postiframe").load(function () {
                iframeContents = this.contentWindow.document.body.innerHTML;
                $("#textarea").html(iframeContents);
            });
$("#postiframe").load(function () {
                iframeContents = this.contentWindow.document.body.innerHTML;
                $("#textarea").html(iframeContents);
            });