JavaScript& jQuery和使用句点 [英] JavaScript & jQuery and the use of periods

查看:67
本文介绍了JavaScript& jQuery和使用句点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑何时在引用类名前使用类名。
在这个例子中,为什么第一次使用'active-slide'类的时候会预先使用一段时间,而另外两个不使用?

  var main = function(){
$('。dropdown-toggle')。click(function(){
$('。dropdown-menu')。toggle();
});

$('。arrow-next')。click(function(){
var currentSlide = $('。active-slide'); //期间
var nextSlide = currentSlide.next();

currentSlide.fadeOut(600);
currentSlide.removeClass('active-slide'); //无句点

nextSlide .fadeIn(600);
nextSlide.addClass('active-slide'); //无句点
});
}

$(document).ready(main);


解决方案

字符是一个选择器。它允许你选择带有'active-slide'类的所有DOM元素。
$ b

jQuery语法 $('')使用选择器返回jQuery包装的元素。



当您添加/删除类时,您没有使用选择器。你实际上删除了一个实际上是'active-slide'的类名(no


I am confused when to use the period before the class names when referencing them. In this example why does the first use of the 'active-slide' class use a period beforehand while the other two do not?

var main = function(){
$('.dropdown-toggle').click(function(){
    $('.dropdown-menu').toggle();
    });

$('.arrow-next').click(function(){
    var currentSlide = $('.active-slide'); //period
    var nextSlide = currentSlide.next();

    currentSlide.fadeOut(600);
    currentSlide.removeClass('active-slide'); //no period

    nextSlide.fadeIn(600);
    nextSlide.addClass('active-slide'); //no period
    });
}

$(document).ready(main);

解决方案

The . character is a selector. It allows you to select ALL DOM elements with that ('active-slide') class.

The jQuery syntax $('') uses selectors to return jQuery wrapped elements.

When you are adding/removing classes, you are not using a selector. You are literally removing a classname which is actually 'active-slide' (no .)

这篇关于JavaScript& jQuery和使用句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆