The problem you're facing is that there is no toggle event; toggle() is a jQuery method. To implement a toggle(), with on() I think you'd need to use a click event, and then an if statement to test whether something's been toggled on, or toggled-off/not-toggled$('#wrap').on('click', '#image', function(){ if (!$(this).attr('data-toggled') || $(this).attr('data-toggled') == 'off'){ /* currently it's not been toggled, or it's been toggled to the 'off' state, so now toggle to the 'on' state: */ $(this).attr('data-toggled','on'); // and do something... } else if ($(this).attr('data-toggled') == 'on'){ /* currently it has been toggled, and toggled to the 'on' state, so now turn off: */ $(this).attr('data-toggled','off'); // and do, or undo, something... }}); 这篇关于.on()&切换在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-07 10:22