簡體   English   中英

jQuery $ .submit和文件在IE和FF中不起作用

[英]jQuery $.submit and files not working in IE and FF

<?php
    if (!empty($_FILES)){
        echo "<pre>";
        echo $_FILES['file']['type'];
        echo "</pre>";
        return;
    }
?>
<script type="text/javascript">
    function autoUpLoad(){
        $("#txtHint").html("<center><img src='include/images/loader.gif' />Reading selected file...</center>");
        $(document).ready(function(){
            $("#file").change(function(){
                $("#myForm").submit(function(data){
                    $("#txtHint").html(data);
                });
            });
        });
    }
</script>
<form id="myForm" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id = "file" onchange='autoUpLoad()'/>
    <input type="submit" value="Send" />
</form>
<div id="txtHint">
    test
</div>

上面的代碼不起作用,我不確定這里有什么問題? 它僅在我刪除這些行時才有效:

function(data){
    $("#txtHint").html(data);
}

它只是不允許我將數據返回到txtHint 任何人都可以向我解釋如何使它工作?

您正在綁定提交事件,而不是觸發它。

帶有回調作為參數的.submit()方法用於綁定提交事件,不帶參數來觸發提交事件。

你應該做以下的事情:

$(document).ready(function () {
    $("#myForm").submit(function (data) {
        $("#txtHint").html(data);
    });
    $("#file").change(function () {
        $("#myForm").submit();
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM