相关疑难解决方法(0)

jQuery相当于JavaScript的addEventListener方法

我试图找到这个JavaScript方法调用的jQuery等价物:

document.addEventListener('click', select_element, true);
Run Code Online (Sandbox Code Playgroud)

我已经达到了:

$(document).click(select_element);
Run Code Online (Sandbox Code Playgroud)

但这并没有达到与JavaScript方法的最后一个参数相同的结果 - 一个布尔值,指示事件处理程序是否应该在捕获或冒泡阶段执行(根据我的理解来自http://www.quirksmode.org) /js/events_advanced.html) - 被遗漏了.

如何使用jQuery指定该参数或以其他方式实现相同的功能?

javascript jquery events event-handling javascript-events

181
推荐指数
6
解决办法
40万
查看次数

innerHTML之后addEventListener不起作用

我在业余时间正在编写一个简单的基于文本的游戏。这就是所谓的TARDIS飞行(Doctor Who!),我正在主菜单上工作。

因此,在设置主菜单的后,我使用的功能addMainMenuListeners通过添加所有事件监听器。 一切正常,直到从子菜单之一返回主菜单为止。然后,我发现按钮不再起作用。设置了之后,我正在打电话,但是即使我这样做了,并且我在控制台中进行了检查,但我没有发现任何事件。 代码: 在我的主要javascript文件中:addEventListenerinnerHTML

addMainMenuListenersinnerHTML


function addMainMenuListeners()
{
    if($("start")) $("start").addEventListener("click", startGame);
    if($("instructions")) $("instructions").addEventListener("click", instructions);
    if($("settings")) $("settings").addEventListener("click", settings);
    if($("back")) $("back").addEventListener("click", resetMainMenu);
    if($("volume")) $("volume").addEventListener("change", function(){saveAndChangeVolume($("volume").value);});
}

function instructions()
{
    $("mainmenu").innerHTML = "<h1>Instructions</h1><p>Fly your TARDIS through the time vortex using the console.  Make sure that you use the correct materialization codes.  Try to keep the time-space coordinates close to the values of the ones given.  AND DON'T CREATE PARADOXES, WHATEVER YOU DO!</p><button id='back'>Back</button>";
    addMainMenuListeners();
    return true; …
Run Code Online (Sandbox Code Playgroud)

html javascript

2
推荐指数
1
解决办法
3218
查看次数