appendTo不在jquery-ui 1.8中工作

时间:2010-10-18 21:13:47

标签: javascript jquery jquery-ui

我有这个小部件,我试图将this.helper附加到我的身体。我在最后使用了$ .extend()函数,但我不知道这是否适用于jquery 1.8,因为我刚刚更新到1.8并且一切都出错了所以我一直在试图让它工作。我的this.helper没有附加到我的身体。有人可以帮忙吗?谢谢!

$.widget("ui.boxTool", $.extend({}, $.ui.mouse, {

        _create: function() {
            this.element.addClass("ui-boxTool");
            this.dragged = false;

            this._mouseInit();
            this.width = $('#toPinpoint').width();
            this.height = $('#toPinpoint').height();

            this.helper = $(document.createElement('div'))
              .css({border:'1px dashed #c2c0c0'})
              .css({cursor:'crosshair'})
              .addClass("ui-boxTool-helper");
          },

          destroy: function() {
            this.element
              .removeClass("ui-boxTool ui-boxTool-disabled")
              .removeData("boxTool")
              .unbind(".selectable");
            this._mouseDestroy();

            return this;
          },

      _mouseStart: function(event) {
        var self = this;

        this.opos = [event.pageX, event.pageY];

        if (this.options.disabled)
          return;

        var options = this.options;

        this._trigger("start", event);

        $(options.appendTo).append(this.helper);

        this.helper.css({
          "z-index": 100,
          "position": "absolute",
          "left": event.clientX,
          "top": event.clientY,
          "width": 0,
          "height": 0
        });
      },

      _mouseDrag: function(event) {
        var self = this;
        this.dragged = true;

    ...

        return false;
      },

      _mouseStop: function(event) {
        var self = this;

        this.dragged = false;

        var options = this.options;

        var clone = this.helper.clone()
          .removeClass('ui-boxTool-helper').appendTo(options.appendTo);



        this._trigger("stop", event, { box: clone });

        this.helper.remove();
        //$('.view-mode').remove(this.helper);
        return false;
      }

    }));
$.extend($.ui.boxTool, {
          defaults: $.extend({}, $.ui.mouse.defaults, {
            appendTo: 'body',
            distance: 0
          })
        });

1 个答案:

答案 0 :(得分:1)

最简单的解决方案是简单地改变线

$(options.appendTo).append(this.helper);

$(this.element).append(this.helper);