简体   繁体   English

我需要帮助将 jquery 转换为正常 javascript

[英]i need help to convert jquery to normal javascript

i have a chat extension for phpBB forum software.我有一个 phpBB 论坛软件的聊天扩展。 over roughly the last 2 years, i've developed some memory and learning problems.在大约过去 2 年中,我开发了一些 memory 和学习问题。 i have a little jquery mixed with my js and part of the jquery code doesn't execute in firefox as if it simply doesn't exist to toggle the display of the bbcode, smilies, and a font colour hold option.我有一点ZD223E143918E478349D52476506C22EZ与我的JS和一部分ZD223E143E18E478349D52476506C22EZ CODE混合在一起。 no errors or anything come up in the browser console but works perfectly in chrome, edge, and other browsers.浏览器控制台中没有错误或任何内容,但在 chrome、edge 和其他浏览器中完美运行。 what i need converted to normal js is this我需要转换为普通js的是这个

$(window).on('load', function () {
    $("#smilies").click(function () {
        $("#chat_smilies").toggle(600);
    });
    $("#bbcodes").click(function () {
        $("#chat_bbcodes").toggle(600);
    });
    $("#chat_bbpalette").click(function () {
        $("#chat_colour_palette").toggle(600);
    });
});

what the above does is a slide effect instead of just popping up the respective elements.上面所做的是幻灯片效果,而不仅仅是弹出相应的元素。 i know the element ids are all where they should be to match with the jquery as it works fine with other browsers.我知道元素 id 都应该与 jquery 匹配,因为它可以与其他浏览器一起正常工作。 is this just a bug with firefox or what?这只是 firefox 的错误还是什么? but if someone could help, it would be greatly appreciated.但如果有人可以提供帮助,将不胜感激。

 const $ = document.querySelector.bind(document); function toggle(duration) { const { style } = this; const { opacity } = style; this.style.transition = `opacity ${duration / 1_000}s`; this.style.opacity = opacity == '' || opacity == 1? 0: 1; } window.onload = () => { $('#smilies').addEventListener('click', toggle.bind($('#chat_smilies'), 600)); $('#bbcodes').addEventListener('click', toggle.bind($('#chat_bbcodes'), 600)); $('#chat_bbpalette').addEventListener('click', toggle.bind($('#chat_colour_palette'), 600)); }
 <button id="smilies">smilies</button> <p id="chat_smilies">chat_smilies</p> <button id="bbcodes">bbcodes</button> <p id="chat_bbcodes">chat_bbcodes</p> <button id="chat_bbpalette">chat_bbpalette</button> <p id="chat_colour_palette">chat_colour_palette</p>

after reading the replies and a ton of reading, i finally found where the issue was.在阅读了回复和大量阅读之后,我终于找到了问题所在。 and it was stupidly simply.这是愚蠢的简单。 the code i have posted is fixed completely by replacing it with the following我发布的代码已通过将其替换为以下内容完全修复

        $("#smilies").click(function(event) {
            $("#chat_smilies").toggle(600);
        });
        $("#bbcodes").click(function(event) {
            $("#chat_bbcodes").toggle(600);
        });
        $("#chat_bbpalette").click(function(event) {
            $("#chat_colour_palette").toggle(600);
        });

and removing the initial function entirely并完全删除初始 function

$(window).on('load', function () {
   button code here
});

found the main issue from this post Jquery toggle not working in Firefox从这篇文章中找到了主要问题Jquery 切换在 Firefox 中不起作用

thank you all:)谢谢你们:)

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

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