$(document).on('click', '.xdi', function(event) { if (!$(event.target).closest('.xdi').length) { $('.addclass').removeClass('addclass'); } }); $(document).on('click', function(event) { if (!$(event.target).closest('.xdi').length) { $('.addclass').removeClass('addclass'); } }); With this code, when you click on any element inside the document, it checks if the clicked element or its ancestors have the class "xdi". If not, it removes the "addclass" from elements with the class "addclass".

jQuery: Toggle 'addclass' on Click and Remove on Outside Click

原文地址: https://www.cveoy.top/t/topic/qosD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录