Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.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
Javascript 满足条件时在jquery中切换类_Javascript_Jquery - Fatal编程技术网

Javascript 满足条件时在jquery中切换类

Javascript 满足条件时在jquery中切换类,javascript,jquery,Javascript,Jquery,我有一些用JavaScript编写的代码,在满足条件时更改CSS类 对于我的站点来说,这个和许多其他JavaScript的问题是,我需要开始用JQuery编写它们 我不得不重写这篇文章的原因是因为Internet Explorer忽略了classList.add&classList.remove 我开始阅读JQuery,但在此之前,你们中的一位能够将以下代码转换为JQuery 我不会告诉你我已经走了多远,因为这里一团糟: JAVASCRIPT代码: 谢谢你抽出时间 使用开关切换类将完成以下操作:

我有一些用JavaScript编写的代码,在满足条件时更改CSS类

对于我的站点来说,这个和许多其他JavaScript的问题是,我需要开始用JQuery编写它们

我不得不重写这篇文章的原因是因为Internet Explorer忽略了classList.add&classList.remove

我开始阅读JQuery,但在此之前,你们中的一位能够将以下代码转换为JQuery

我不会告诉你我已经走了多远,因为这里一团糟:

JAVASCRIPT代码:

谢谢你抽出时间

使用开关切换类将完成以下操作:

$('.nowPlayNoAnimate').each(function() {
  $(this).toggleClass('nowPlayAnimate', $(this).parent().width() < $(this).width());
});

嗨,它们是不同的nowPlayNoAnimate和nowPlayAnimateIf你不支持IE6/7,你可以polyfill.classList。如果您支持IE8,我假设您已经插入了.getElementsByClassName。
$('.nowPlayNoAnimate').each(function() {
  $(this).toggleClass('nowPlayAnimate', $(this).parent().width() < $(this).width());
});