jQuery Sortable-如何获取当前拖动的元素属性 [英] jQuery Sortable - How to get current dragged element attribute

查看:230
本文介绍了jQuery Sortable-如何获取当前拖动的元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqueryui可排序小部件.我需要获取当前拖动元素的数据属性. $(this).data('attribute_name')在这里不起作用.我还尝试了其他方法,但未获得正确的结果.

I am using jqueryui sortable widget. I need to get the current dragged element's data attribues. $(this).data('attribute_name') is not working here. I have also tried some other methods, but not getting the correct result.

HTML

<ul class="draggable-item" style="min-height:10px;">
   <li data-parent="31" data-id="81" class="ui-state-default">Label</li>
   <li data-parent="31" data-id="86" class="ui-state-default">Max Value</li>
   <li data-parent="31" data-id="83" class="ui-state-default">Unit</li>
   <li data-parent="31" data-id="84" class="ui-state-default">Warning Level High</li>
   <li data-parent="31" data-id="85" class="ui-state-default">Warning Level Low</li>
</ul>

JS

$(document).ready(function() {
  $(".draggable-item").sortable({
    start: function( event, ui ) { 
      //Here i need to get current dragged element's 'parent' attribue.
      //console.log(ui.item[0].attributes); - Here i got the entire attribute values in an array. But the order of the array is different in browsers.
    },
  }).disableSelection();
});

推荐答案

尝试$(ui.item).data('attribute_name');$(event.currentTarget).data('attribute_name');

这篇关于jQuery Sortable-如何获取当前拖动的元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆