简体   繁体   English

未捕获的TypeError:对象不是函数(调用onchange函数)

[英]Uncaught TypeError: object is not a function (calling onchange function)

My code is big so I will keep it short. 我的代码很大,因此我将使其简短。 I am tring to fire onchange event of Select atribute. 我正在尝试触发Select atribute的onchange事件。 Problem is that when I fire it I got this error: 问题是,当我解雇它时,我得到了这个错误:

Uncaught TypeError: object is not a function

Since my code is big I will show to you codes where I decalare onchange event and when I fire it. 由于我的代码很大,因此我将向您显示代码,这些代码将在onchange事件中进行贴花和何时触发。

Here is when onchange function is declared: 这是声明onchange函数的时间:

 function e(b, c) {
        function a() {
            if (b.current_modal) {
                b.current_modal.className = "hide"
            }
            f("overlay").className = "hide"
        }
        jigsaw.UI.close_lightbox = a;
        Util.$("overlay").click(a);
        Util.$("set-parts").change(function () {
            if (this.parts != 9) {
                jsaw.set_image("images/puzzle.jpeg")
            } else {
                jsaw.set_image("images/puzzle1.jpeg")
            }
            c.emit(jigsaw.Events.PARTS_NUMBER_CHANGED, +this.value);
            c.emit(jigsaw.Events.RENDER_REQUEST)
        });
        Util.$("game-options").click("a", function (h) {
            if (jigsaw.Events[this.id]) {
                h.preventDefault();
                c.emit(jigsaw.Events[this.id])
            }
        })
    }

and here is when I fire onchange event: 这是我触发onchange事件的时间:

show_time: function () {
           /*.....*/

        javascript: document.getElementById("date").innerHTML = ScoreResult;
        document.getElementById("set-parts").selectedIndex = 1;
        document.getElementById('set-parts').onchange();


    }

I don't use jquery, but in JavaScript there is a difference on how addEventListener( eventName , ...) and on*eventName* = function(){} works. 我不使用jquery,但是在JavaScript中,addEventListener( eventName ,...)和on * eventName * = function(){}的工作方式有所不同。

I suppose that not modern library will use on*eventName* interface for one simple reason: I can hold just a single listener. 我想不是现代图书馆会因为一个简单的原因而使用on * eventName *接口:我只能容纳一个侦听器。 But the on*eventName* are still there to support legacy code. 但是on * eventName *仍然可以支持旧版代码。

Now, in your particular case, when you add the event your library is using the addEventListener/removeEventListener/dispatchEvent underline DOM interface. 现在,在特定情况下,添加事件时,您的库将使用addEventListener / removeEventListener / dispatchEvent下划线DOM接口。 This will not set up the legacy on*eventName* property to your callback, so the only way you can directly call it it by dispatching an event with the DOM method dispatchEvent (or your library wrapper) with an Event object with type 'change'. 这不会为您的回调设置旧版on * eventName *属性,因此,您可以通过使用DOM方法dispatchEvent(或您的库包装器)使用事件类型为'change'的DOM事件调度事件来直接调用它的唯一方法。 That is what "new Event('change')" does. 这就是“新事件(更改)”所做的。 If you need to pass extra properties to the event you can create it like this: 如果您需要将额外的属性传递给事件,则可以这样创建它:

new Event('change', { foo : 1, bar : 'hello, world!' })

and those properties will be available in your listener callback arguments[0] under whichever name you set your argument (in your case, you left it empty). 并且这些属性将在您设置参数的名称下的侦听器回调参数[0]中可用(在您的情况下,您将其保留为空)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM