我想创建一个自定义元素,其中包含使用辅助函数从“被拖动”元素中获取的文本.我的问题是ui未定义,所以我不知道如何掌握拖拽的来源.
$('.draggable').draggable({
helper: function(event,ui) {
var foo = $('<span style="white-space:Nowrap;">DRAG TEST</span>');
return foo;
}
});
解决方法
您正在应用的辅助功能
is invoked the following way:
$(o.helper.apply(this.element[0],[event]))
这意味着这指的是你想要在该函数中使用的.draggable,例如:
$('.draggable').draggable({
helper: function(event) {
return $('<span style="white-space:Nowrap;"/>')
.text($(this).text() + " helper");
}
});
You can test it out here.