3

我编写了以下代码:

HorizontalPanel draggable = new HorizontalPanel();
Function startDragParent = new Function () {
    @Override
    public boolean f (Event e) {
    // some code here...
    return false;
}
};
Function dragParent = new Function () {
    @Override
    public boolean f (Event e) {
    // some code here...
    return false;
}
};
Function stopDragParent = new Function () {
    @Override
    public boolean f (Event e) {
    // some code here...
    return false;
}
};
$(draggable).as(Ui).draggable()
    .bind(Draggable.Event.start, startDragParent);
    .bind(Draggable.Event.drag, dragParent);
    .bind(Draggable.Event.stop, stopDragParent);

HorizontalPanel childDraggable = new HorizontalPanel();
Function dragChild = new Function () {
    @Override
    public boolean f (Event e) {
    // some code here...
    return false;
}
};
$(childDraggable).as(Ui).draggable().bind(Draggable.Event.drag, dragChild);

// finally I add one element inside another
draggable.add(childDraggable);

当我开始拖动内部元素时,我的问题就开始了,然后可拖动(childDraggable 的父级)也开始拖动(仅在 IE8 中,我猜在以前的版本中)。我想阻止这种事件传播,即我想拖动 innerElement 而不拖动其父级。

我已经尝试过stopPropagationpreventDefault但效果不佳。帮助将不胜感激。

提前致谢。

4

1 回答 1

0

stopPropagation 在 IE 上不起作用,您应该按以下方式使用 cancelBubble 之类的东西:

function stop(e) {
    // feature check (in IE this will be undefined) 
    if (e.stopPropagation) {
        // standards compliant browser
        e.stopPropagation();
    } else {
        // dreadful IE 
        e.cancelBubble = true;
    }
}
于 2013-09-25T19:09:25.913 回答