【问题标题】:"Object doesn't support this property or method" when setting an object property in IE8在 IE8 中设置对象属性时出现“对象不支持此属性或方法”
【发布时间】:2015-08-06 11:01:52
【问题描述】:

我正在尝试在不使用 jQuery 的情况下制作可拖动的元素。我希望它与 IE8 兼容。以下在this.handle = { 处中断并出现错误“对象不支持此属性或方法。”

在设置对象属性时,IE9

var Draggable = function(el){
  this.el = el;
  this.el.style.left = "0px";
  this.el.style.top = "0px";
  this.origin = {};

  this.handle = {
    drag: this.drag.bind(this),
    move: this.move.bind(this)
  };

  this.events = {
    start: new Listener(this.el, ["mousedown", "touchstart"], this.handle.drag),
    move: {},
    end: {}
  };
}
Draggable.prototype = {
  drag: function(evt){
    this.origin.left = parseInt(this.el.style.left) - evt.clientX;
    this.origin.top = parseInt(this.el.style.top) - evt.clientY;
    this.events.move = new Listener(window, ["mousemove", "touchmove"], this.handle.move);
    this.events.end = new Listener(window, ["mouseup", "touchend"], this.drop.bind(this));
  },
  move: function(evt){
    this.el.style.left = this.origin.left + evt.clientX + "px";
    this.el.style.top = this.origin.top + evt.clientY + "px";
  },
  drop: function(){
    this.events.move.stopListening();
  }
}

【问题讨论】:

    标签: javascript internet-explorer cross-browser


    【解决方案1】:

    Function.prototype.bind() 在 IE8 中不受支持。你可以为它写一个polyfill

    【讨论】:

    • 就是这样。谢谢你。我通过 var self = this; 解决了这个问题,我并不为此感到自豪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多