在IE11上工作的事件构造函数?

时间:2017-01-10 18:02:25

标签: javascript internet-explorer-11 web-worker polyfills custom-events

uprs.updateString在IE11中不起作用,遗憾的是,MDN和此问题的填充程序都不起作用:Internet Explorer 9, 10 & 11 Event constructor doesn't work,因为它们依赖于 PreparedStatement statement = conn.prepareStatement (query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ... ResultSet uprs = statement.executeQuery (); ... // Update DB ColumnA with input coming from client uprs.updateString ('ColumnA', unvalidatedUserInput); ... // Updates the underlying database uprs.updateRow();

是否有在工作环境中创建自定义事件的变通方法?

1 个答案:

答案 0 :(得分:0)

使用将现有事件系统的实现别名的方法。例如:

    sinon.Event = function Event(type, bubbles, cancelable, target) {
        this.initEvent(type, bubbles, cancelable, target);
    };

    sinon.Event.prototype = {
        initEvent: function (type, bubbles, cancelable, target) {
            this.type = type;
            this.bubbles = bubbles;
            this.cancelable = cancelable;
            this.target = target;
        },

        stopPropagation: function () {},

        preventDefault: function () {
            this.defaultPrevented = true;
        }
    };

    sinon.CustomEvent = function CustomEvent(type, customData, target) {
        this.initEvent(type, false, false, target);
        this.detail = customData.detail || null;
    };

    sinon.CustomEvent.prototype = new sinon.Event();

    sinon.CustomEvent.prototype.constructor = sinon.CustomEvent;

    sinon.EventTarget = {
        addEventListener: function addEventListener(event, listener) {
            this.eventListeners = this.eventListeners || {};
            this.eventListeners[event] = this.eventListeners[event] || [];
            push.call(this.eventListeners[event], listener);
        },

        removeEventListener: function removeEventListener(event, listener) {
            var listeners = this.eventListeners && this.eventListeners[event] || [];

            for (var i = 0, l = listeners.length; i < l; ++i) {
                if (listeners[i] === listener) {
                    return listeners.splice(i, 1);
                }
            }
        },

        dispatchEvent: function dispatchEvent(event) {
            var type = event.type;
            var listeners = this.eventListeners && this.eventListeners[type] || [];

            for (var i = 0; i < listeners.length; i++) {
                if (typeof listeners[i] === "function") {
                    listeners[i].call(this, event);
                } else {
                    listeners[i].handleEvent(event);
                }
            }

            return !!event.defaultPrevented;
        }
    };
}


/**
 * Used to bind event listeners to the worker. Internally it uses the jQuery `.on` method.
 * @method on
 * @param {Mixed} args* Lookup the jQuery `.on` API for argument list.
 * @chainable
 */

var worker = new WebWorker('./worker-script.js');
worker.on('my-custom-event', function () {
console.log('custom event triggered!');
});

<强>参考