【问题标题】:Get table row ID after dropzone event在 dropzone 事件后获取表行 ID
【发布时间】:2013-04-16 17:32:24
【问题描述】:

我已经为此苦苦思索了好几个小时,希望有人能提供帮助。当文件上传到 dropzone 框中时,我正在尝试获取行 ID 或表单 ID。我有多个带有多个放置区框的表格行。

这是我表中的示例行:

<table class="docs" id="show">      
    <tr class="doc" id="*Need_This*">
        <td>
            <div class="file_upload drop">
                <form class="dropzone clickable" id="*Or_Need_This*">
                </form>
            </div>
        </td>
    </tr>
</table>

这是我的 jquery:

<script type="text/javascript">
$(document).ready(function(){
     $(".dropzone").dropzone({ 
        paramName: 'photos',
        url: "post.php",
        dictDefaultMessage: "Drag or Click",
        clickable: true,
        enqueueForUpload: true,
        init: function() {
            var id = $(this).closest('tr').attr('id');
            this.on("success", function(file) { alert(id); });
          }
    });
});
</script>

现在它返回未定义。我需要获取 id,以便我可以将 css 更改附加到行上的其他元素。非常感谢任何帮助!

【问题讨论】:

    标签: javascript jquery jquery-plugins dropzone.js


    【解决方案1】:

    this 在您的情况下是指 Dropzone 实例,而不是元素本身!如果您需要访问 dropzone 的实际元素,请使用dropzone.element

    所以你可以这样做:var id = $(this.element).etc...

    希望有所帮助。

    【讨论】:

      【解决方案2】:

      在文档中您可以阅读:

      获取服务器响应作为第二个参数

      试试这个:

      this.on("success", function(file,rep) {
           alert(file);
           alert(rep); //The response
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-17
        • 2013-07-01
        相关资源
        最近更新 更多