我想创建一个自定义元素,其中的文本使用辅助函数从“被拖动”的元素中获取。我的问题是 ui 未定义,所以我不知道如何获取拖动的来源。
$('.draggable').draggable({
helper: function(event, ui) {
var foo = $('<span style="white-space:nowrap;">DRAG TEST</span>');
return foo;
}
});
最佳答案
您正在应用的 helper
函数 is invoked the following way :
$(o.helper.apply(this.element[0], [event]))
这意味着 this
引用您想要在该函数内的 .draggable
,例如:
$('.draggable').draggable({
helper: function(event) {
return $('<span style="white-space:nowrap;"/>')
.text($(this).text() + " helper");
}
});
关于jquery - 如何在 jQuery-UI 中使用可拖动功能自定义帮助程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4069348/