在可拖动的jquery UI上添加图标

时间:2014-04-25 11:19:25

标签: javascript jquery jquery-ui

我想添加" +"可拖动项目上的图标或类属性。我正在使用jquery Ui draggable方法。

代码:



    function deptStyleDroppable(){
    $('.deptName').parents("tr").draggable({
        cursor: "move",
        //revert: "invalid", // slide back, when dropping over non-target
        revert: function(dropped){
        // Return `true` to let the helper slide back.
            if(typeof dropped === "boolean"){
                // dropped == true, when dropped over a simple, valid droppable target.
                // false, when dropped outside a drop target.
                return !dropped;
            }
        // Drop comes from another tree. Default behavior is to assume
        // a valid drop, since we are over a drop-target.
        // Therefore we have to make an extra check, if the target node
        // was rejected by a Dynatree callback.
        var helper = $.ui.ddmanager && $.ui.ddmanager.current && $.ui.ddmanager.current.helper;
        var isRejected = helper && helper.hasClass("dynatree-drop-reject");
        return isRejected;          
        },
        connectToDynatree: true,
        cursorAt: { top: -5, left:-5 },
        helper: "clone"
    });
    }


我怎样才能做到这一点。请帮我解决这个问题。

感谢你。

1 个答案:

答案 0 :(得分:0)

Draggable元素在初始化后已经有ui-draggable css类。

但是如果你想添加自己的,只需链接addClass(...)。如果您想添加一个可以与prepend()链接的图标,则相同:

$('.deptName')
    .parents('tr')
    .draggable({ ... })
    .addClass('your-css-class')
    .prepend('<img src="http://path-to-your-icon"/>');

我写了 jsFiddle 来说明。