0

我似乎无法让它在 JavaScript 中工作。我尝试过使用普通的旧 JavaScript 和 JQuery,但似乎没有任何效果。

这是我的情况:我有这个弹出“面板”,其中有一个按钮。该按钮有一个单击事件侦听器,我希望该处理程序触发面板将侦听的自定义事件。这是因为我需要处理面板中按钮单击的所有逻辑。

这就是我正在做的事情:在我启动面板之前,我为我的“类”调用了一个构造函数:

function PopUpStageAsssignmentTaker(content) {
            PopUpStage.call(this);
            this.allPagesAdded = false;
            this.questionsCreated = [];// will be an array of pages that will be submitted
            this.listLabel = null;
            addAssignmentTakerParts.call(this);
            this.popUpDiv.addEventListener("assignmentTakingSubmitEvent", handleAssignmentSubmit, true);

            function handleAssignmentSubmit(event) {
                alert("YESSS!");
            }
        }

这做了很多,但只知道在对 PopUpStage 的调用中,它会创建代表面板的 div 并将其保存在 this.popUpDiv 中。因此,我向 this.popUpDiv 添加了一个事件侦听器,以侦听我正在制作的一些自定义事件。

后来我有在面板中创建内容的代码,我们有这样的东西:

SubmitQuestionTakingPage.prototype.makeContent = function(question) {
                var questionWrapper = getQuestionWrapper();

                var submitDiv = document.createElement("section");
                submitDiv.innerHTML = "Pressing Submit will cause this Assignment to be submitted and you will be unable to make any changes after that. If this " +
                        "Assignment is automatically graded you will receive a Grade upon clicking submit. If this Assignment is not automatically submitted you must wait" +
                        " for the creator of this Assignment to assign you a Grade. To continue, please press Submit.";
                submitDiv.setAttribute("class", "separatedSmaller");
                questionWrapper.appendChild(submitDiv);

                var submitButton = document.createElement("input");
                submitButton.setAttribute("type", "submit");
                submitButton.setAttribute("class", "fancyButton");
                submitButton.addEventListener("click", handleSubmitButtonClick);
                questionWrapper.appendChild(submitButton);


                return questionWrapper;
            };

            function handleSubmitButtonClick(event) {
                 var event = document.createEvent("Event");
                  event.initEvent("assignmentTakingSubmitEvent", true, true);
                  window.dispatchEvent(event);

// $(this).trigger("assignmentTakingSubmitEvent"); }

所以我们创建了一些内容,并在其中创建了一个按钮,该按钮有一个点击监听器。在点击处理程序中,您可以看到我如何触发事件。

问题:我读到这在 IE 版本 9+ 下不起作用。我该怎么做才能使它在所有浏览器中都能正常工作?有办法吗?

4

0 回答 0