点和哈希符号在JQuery中是什么意思? [英] What do dot and hash symbols mean in JQuery?

查看:72
本文介绍了点和哈希符号在JQuery中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下示例中,我对点和哈希符号感到困惑:

I feel confused of the dot and hash symbols in the following example:

<DIV ID="row">
<DIV ID="c1">              
<Input type="radio" name="testing" id="testing" VALUE="1">testing1
</DIV>
</DIV> 

代码1:

 $('#row DIV').mouseover(function(){     
    $('#row DIV').addClass('testing');  
    });

代码2

  $('.row div').mouseover(function(){
        $(this).addClass('testing');
    });​

代码1和2看起来非常相似,所以让我感到困惑
当我应该使用".row div"来指代特定的DIV而不是使用"#row div"吗?

Codes 1 and 2 look very similar, and so it makes me so confused that
when I should use ".row div" to refer to a specific DIV instead of using "#row div" ?

推荐答案

哈希(#)指定根据元素ID选择元素

The hash (#) specifies to select elements by their ID's

点(.)指定按元素的类名选择元素

The dot (.) specifies to select elements by their classname

您可以在此处了解有关选择器的更多信息: http://api. jquery.com/category/selectors/basic-css-selectors/

You can read more about the selectors here: http://api.jquery.com/category/selectors/basic-css-selectors/

这篇关于点和哈希符号在JQuery中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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