Dropzone js无法正常工作

时间:2013-04-24 09:47:37

标签: javascript jquery dropzone.js

如何在不使用表单中的类的情况下使用dropzone。

我基本上希望在表单中包含div并在该div中调用class="dropzone"。但它似乎不起作用。

以下是我的代码:

<!DOCTYPE html>
<html lang="en">
    <head>
    <title></title>
    <link rel="stylesheet" href="css/basic.css" />
    <link rel="stylesheet" href="css/dropzone.css"/>
    <script src="dropzone.min.js"></script>
    <script type="text/javascript">
        var myDropzone = new Dropzone("div#myId", { url: "file-upload"})
    </script>

    <body>
        <form action="upload.php">
            <input type="text">
            <div id="myId" class="dropzone"></div>
        </form>
    </body>
</html>

2 个答案:

答案 0 :(得分:2)

当DOM准备就绪时启动.ready事件并使用这样的事件。

<!DOCTYPE html>
<html lang="en">
    <head>
    <title></title>
    <link rel="stylesheet" href="css/basic.css" />
    <link rel="stylesheet" href="css/dropzone.css"/>
    <script src="dropzone.min.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function() 
        {
            var myDropzone = new Dropzone("div#myId", { url: "file-upload"});
        });
    </script>

    <body>
        <form action="upload.php">
            <input type="text">
            <div id="myId" class="dropzone"></div>
        </form>
    </body>
</html>

答案 1 :(得分:-1)

你的url参数没有指向任何有效的php文件。我相信你的代码应该是

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" href="css/basic.css" />
<link rel="stylesheet" href="css/dropzone.css"/>
<script src="dropzone.min.js"></script>
<script type="text/javascript">
    var myDropzone = new Dropzone("div#myId", { url: "upload.php"}) //according to your forms action
</script>

<body>
    <form action="upload.php">
        <input type="text">
        <div id="myId" class="dropzone"></div>
    </form>
</body>