Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除jquery中未运行的类_Jquery - Fatal编程技术网

删除jquery中未运行的类

删除jquery中未运行的类,jquery,Jquery,我的代码 if($("#edButtonHTML").is(".active")) { $("#edButtonHTML").removeClass("active"); $("#edButtonPreview").addClass("active"); } 如果($(“#edButtonHTML”)。为(“.active”)) { $(“#edButtonHTML”).removeC

我的代码

if($("#edButtonHTML").is(".active")) { $("#edButtonHTML").removeClass("active"); $("#edButtonPreview").addClass("active"); } 如果($(“#edButtonHTML”)。为(“.active”)) { $(“#edButtonHTML”).removeClass(“活动”); $(“#edButtonPreview”).addClass(“活动”); } 我需要从元素#edButtonHTML中删除活动类,并添加到#EdButtonView中
不幸的是,无法正常工作…请帮助我将您的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,我们无法提供明确的答案。但有几点建议:

  • 使用JavaScript调试器(我喜欢Firebug)在“if”条件中设置一个断点,以查看代码执行是否达到该条件

  • 如果您确信删除功能不起作用,可以在JQuery论坛上发布问题,或者在JQuery站点上提交错误报告


  • 你确定你的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");
            }