简体   繁体   English

将香草js转换为jquery

[英]Convert vanilla js to jquery

I have a problem in converting my websites vanilla js to jQuery我在将我的网站 vanilla js 转换为 jQuery 时遇到问题
I want to convert我想转换

const blue = $('#color-blue'),
       red = $('#color-red');

blue.addEventListener('click', () => {
    delete chat.dataset.color;
});
red.addEventListener('click', () => {
    chat.dataset.color = 'red';
});

to use with jquery与 jquery 一起使用

While it is unnecessary to change the event listeners to jQuery, if for some reason you still want this, the below should work for you!虽然没有必要将事件侦听器更改为 jQuery,但如果由于某种原因您仍然想要这个,下面的内容应该适合您!

const blue = $('#color-blue'),
    red = $('#color-red');

blue.on('click', () => delete chat.dataset.color);
red.on('click', () => chat.dataset.color = 'red');

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

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