触发事件处理程序附加到它自己的对象,但在链中?

时间:2010-10-26 16:56:43

标签: javascript jquery events user-interface chaining

现在我有:

$("#myElement").bind("buildTimeline", function (event, newViewObj) {
    curDomObj = $(this).children(".timeline"); //this refers to #myElement

    curDomObj.draggable({
        axis:"x",
        drag:curDomObj.trigger("drag")
    });
});

我宁愿只有一条链,但是有没有办法在链中的位置引用当前元素?:

$(this).children(".timeline").draggable({
    axis:"x",
    drag:$(this).trigger("drag") //this still refers to #myElement, but I want
                                 //it to refer to #myElement .timeline
});

1 个答案:

答案 0 :(得分:0)

怎么样:

$("#myElement").bind("buildTimeline", function (event, newViewObj) {
    $(this).children(".timeline").draggable({
        axis:"x",
        drag:$(this).children(".timeline").trigger("drag")
    });
});