MY 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.
答案 0 :(得分:2)
使用this
对象访问ID
var ancId=$(this).attr('id');
var dataNeed=$(this).attr('data-need');
在draggable
回拨功能
快乐编码:)