Tes*_*ate 2 javascript jquery jquery-ui jquery-ui-draggable
在Jquery UI的网站上:
http://jqueryui.com/demos/draggable/
如果我有:
<div id="someId" class="someClass">he</div>
<div id="otherId" class="otherClass">he2</div>
Run Code Online (Sandbox Code Playgroud)
和:
$('#someid','#otherid').draggable({
drag: function(event, ui) {
alert(ui.helper.THEIDOFTHECLICKEDITEM); // What goes here?
}
});
Run Code Online (Sandbox Code Playgroud)
如何使用回调中的"ui"变量获取ID的ID或类?如果不可能,我如何从"event"变量中获取它?
你要:
$("#someId, #otherId").draggable({
drag: function(event, ui) {
console.log(ui.helper[0].id);
}
});
Run Code Online (Sandbox Code Playgroud)
(或使用ui.helper.attr("id"))
注意:ui.helper是一个jQuery对象,这就是为什么我们必须使用它.attr("...")来检索id或访问索引0处的匹配元素并直接获取id.
或者不使用ui参数(可能是我推荐的):
$("#someId, #otherId").draggable({
drag: function(event, ui) {
console.log(this.id); // "this" is the DOM element being dragged.
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个有效的例子:http://jsfiddle.net/andrewwhitaker/LkcSx/
| 归档时间: |
|
| 查看次数: |
4397 次 |
| 最近记录: |