简体   繁体   English

我想将我的 Javascript 转换为 jQuery 并使用 Class 名称

[英]I want to convert my Javascript to jQuery and work with Class name

I have a autoclick script which is made with javascript codes.我有一个使用 javascript 代码制作的自动点击脚本。 It is working only with ID.它仅适用于 ID。 Not working with Class.不适用于 Class。 I want to convert it to jQuery and working with class.我想将其转换为 jQuery 并使用 class。 Please help me..请帮我..

 <a href="https://stackoverflow.com" id="autoclick">Autoclick</a> <script type="text/javascript"> var autoclickBtn = document.getElementById("autoclick"); autoclickBtn.addEventListener("click", () => { console.log("Button clicked"); }); var interval = window.setInterval(() => { autoclickBtn.click(); }, 2000); </script>

You just need a jQuery selector and instead of addEventListener() , you may use either click() or on() .您只需要一个 jQuery 选择器,而不是addEventListener() ,您可以使用click()on()

 $('.autoclick').on("click", () => { console.log("Button clicked"); }); window.setInterval(() => { $('.autoclick')[0].click(); }, 2000);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="https://stackoverflow.com" class="autoclick">Autoclick</a>

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

相关问题 我现有的代码是javascript,我想在jquery中转换这些代码? - my existing code is javascript and i want to convert these in jquery? 我想将 jquery function 转换为 javascript - I want to convert a jquery function to javascript 类列表显示错误。 我正在使用色板来选择变体,我想将jQuery转换为纯javascript以进行选择? - Class list is showing error. I am using swatch to select variant I want to convert jQuery to pure javascript to select? 我想在不使用jquery的情况下在我的页面上使用文本计数器吗? - I want a text counter to work on my page without using jquery? 我希望我的jQuery动画只能工作一次 - I want my jQuery animation to work only once 我想将页面上的Flash元素转换为javascript / jquery ...? - I want to turn this flash element on my page into javascript/jquery…? 我想在没有jQuery的情况下从javascript附加html - I want to append my html from javascript without jQuery 我想检查我的 id 或 class 是否存在于表中 | JavaScript - I want to check if my id or class exists in a table | JavaScript 我只希望在文本框中输入数字(我只希望使用输入ID或类) - I want only numeric in my text box (I want only work with input id or class) 想要将jquery代码转换为纯JavaScript或AngularJS - Want to convert the jquery code to pure JavaScript or AngularJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM