如何通过在JQuery中使用stop事件来获取可拖动元素的标识符?

时间:2022-12-20 20:38:58

I have the following code

我有以下代码

<div id="container">
    <div id="_01">1° item</div>
    <div id="_02">2° item</div>
    <div id="_03">3° item</div>
    <div id="_04">4° item</div>
</div>

So in my js code

所以在我的js代码中

$("#container div").draggable({
    stop:function(e, ui) {

    }});

What i have to put in stop event in order to get the identifier of a draggable element ?

为了获得可拖动元素的标识符,我必须在stop事件中放入什么?

regards,

2 个解决方案

#1


$("#container div").draggable({
    stop:function(e, ui) {
       alert("id=" + $(this).attr("id");
    }});

#2


Have you tried:

你有没有尝试过:

$(this)  // this should be the current element

#1


$("#container div").draggable({
    stop:function(e, ui) {
       alert("id=" + $(this).attr("id");
    }});

#2


Have you tried:

你有没有尝试过:

$(this)  // this should be the current element