删除jquery中未运行的类
我的代码 if($("#edButtonHTML").is(".active")) { $("#edButtonHTML").removeClass("active"); $("#edButtonPreview").addClass("active"); } 如果($(“#edButtonHTML”)。为(“.active”)) { $(“#edButtonHTML”).removeClass(“活动”); $(“#edButtonPreview”).addClass(“活动”); } 我需要从元素#edButtonHTML中删除活动类,并添加到#EdButtonView中删除jquery中未运行的类,jquery,Jquery,我的代码 if($("#edButtonHTML").is(".active")) { $("#edButtonHTML").removeClass("active"); $("#edButtonPreview").addClass("active"); } 如果($(“#edButtonHTML”)。为(“.active”)) { $(“#edButtonHTML”).removeC
不幸的是,无法正常工作…请帮助我将您的if条件更改为[假设您的类名为active]
if($("#edButtonHTML").hasClass("active"))
{
$("#edButtonHTML").removeClass("active");
$("#edButtonPreview").addClass("active");
}
不要认为if语句会解决问题。您可以始终在if中添加一条alert语句以进行检查。 另一个选项是hasClass(“活动”),因此
我的建议是采取一些老派的方法。在if语句中添加一个警告语句,看看它是否真的被提出了
alert("Before if condition.");
if($("#edButtonHTML").is(".active"))
{
alert("Condition was satisfied");
$("#edButtonHTML").removeClass("active");
$("#edButtonPreview").addClass("active");
}
老式,但它可以用于调试。但您可以使用firebug、IEDebugbar或任何其他浏览器调试工具来检查您的javascript是否工作正常。由于您没有发布HTML,我们无法提供明确的答案。但有几点建议:
你确定你的if条件满足吗?使用alter语句来检查这个问题你是否使用firebug之类的浏览器调试工具检查过这个类是否真的被删除了?或者你是否检查过这个条件是否真的在if语句中了?它对我不起作用,即使我使用了hasClass我使用的是jquery.Actual.hasClass的更新版本(“active”)是检查类的更好方法,但是.is(“.active”)同样有效。我想这里的问题是,条件满足了吗,或者是带有edButtonHTML的元素在页面中找到了一个名为active的类。是的,这是真的。我的第一条评论与显示alert的问题相同,但我没有删除类。我听说jquery新版本有时使用removeClassjQuery JavaScrip无法正常运行t库v1.4.2
alert("Before if condition.");
if($("#edButtonHTML").is(".active"))
{
alert("Condition was satisfied");
$("#edButtonHTML").removeClass("active");
$("#edButtonPreview").addClass("active");
}