簡體   English   中英

如何使用 Jquery Draggable 事件檢索“id”和“data”值

[英]How to retrieve “id” and “data” value using Jquery Draggable events

我的jQuery代碼:

$(document).ready(function() {
     $( ".thumblink" ).draggable({
      stop: function( event, ui ) {
          var pos_x = ui.offset.left;
          var pos_y = ui.offset.top;
            console.log($(this).attr('id'));
            console.log($(this).attr('data-need'));
       $.ajax({
            type:"POST",
            url:"save.php",
            data:{x:pos_x,y:pos_y}
            });
            
          },
      containment: "parent",
      cursor: 'move'
    });

我的 HTML 代碼;

<a href="" class="thumblink"  data-need="12" "id="imglink1"><img src="rest/o.png width='50' height='50' border="0"/></a>


console.log($(this).attr('id')); gives me null value
console.log($(this).attr('data-need')); undefined value
How to retrieve my anchor tag "id" and "data need" value please help.

使用this對象訪問 id

var ancId=$(this).attr('id'); var dataNeed=$(this).attr('data-need');

draggable回調函數的停止函數中調用它

快樂編碼:)

暫無
暫無

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

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