奇怪的问题,jQuery .removeClass()没有做任何事情 [英] Odd issue with jQuery .removeClass() not doing anything
问题描述
我有一些代码添加类到一个元素,然后尝试删除它们,并添加不同的1秒后。我得到一些非常奇怪的行为,我甚至不能在一个简单的中看到。
编辑2 :已确认为 尝试使用 演示: 希望这有助于我们,如果您有任何问题,请告诉我们! I have some code that adds classes to an element and then tries to remove them and add different ones 1 second later. I'm getting some very odd behavior that I can't even reproduce in a simple jsfiddle example. Here's the relevant JavaScript code I have: And here is what the console is saying: As you can see, adding the If it were an issue of context or Additional info: jQuery latest (v.1.9.0 I think), jQuery UI v 1.10.0, Chrome v.24.0.1312.56 m Edit: The problem appears to be directly related to jQuery UI, and can be seen happening in this fiddle. Edit 2: This was confirmed as a bug in jQuery, and has been fixed. Try using DEMO: Hope this helps and let me know if you have any questions! 这篇关于奇怪的问题,jQuery .removeClass()没有做任何事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! .removeAttr('class')
而不是 .removeClass()
。
console.log('before destroyed: ' + currentTile.get(0).className);
currentTile.addClass(classes.destroyed);
console.log('after destroyed: ' + currentTile.get(0).className);
setTimeout(function () {
console.log('before blanking: ' + currentTile.get(0).className);
currentTile.removeClass().addClass(classes.blank + ' ui-draggable');
console.log('after blanking: ' + currentTile.get(0).className);
}, 2000);
destroyed
class works fine, but the call to removeClass()
inside of the setTimeout
appears to be doing nothing, and then the .addClass(classes.blank + ' ui-draggable');
also appears to be working fine. Also, if I pass a single class to removeClass
it removes that one class without a problem.currentTile
being the wrong element, I would think the addClass
would also fail? Anyone have any idea what is going on here?
.removeAttr('class')
rather than .removeClass()
.