• js中的$符号代表什么


    js中的$符号代表什么

    一、总结

    1、$:相当于document.getElementById(...)

    2、$常用用法:每句话意思下面有,好东西

      $("div p"); // (1)
    
      $("div.container"); // (2)   
    
        $("div #msg"); // (3)   
    
        $("table a",context); // (4)

    二、在js中 $是什么意思?

    jquery里的语法规则。相当于document.getElementById(...)

    你看的是框架吧 一般用做替换document.getElementById
    不过那都是自己定义的 本身没什么意思

    在 prototype 和DWR 的JS 类库里也有这个符号,在这两个类库里的这个符号是代表 document.getElementByIdx()这个函数。为了达到document.getElementByIdx() 这个函数的效果,JQuery 也试用了 $() 这个符号。 例:   var someElement = $("#myId"); 看起来比其他两个框架的要多了一个“#” 。 好,看看下面的用法:

      $("div p"); // (1)

      $("div.container"); // (2)   

    $("div #msg"); // (3)   

    $("table a",context); // (4)

    在prototype里看过这样的写法吗?第一行代码得到所有标签下的P元素第二行代码得到class 为container的元素, 第三行代码得到标签下面id为msg的元素第四行代码得到context为上下文的table里面所有的连接元素。如果你熟悉CSS,你会觉得这些写法很眼熟!对了。正是。看出奥妙了吧。jquery就是通过这样的方式来找到Dom对象里面的元素跟CSS的选择器相类似
  • 相关阅读:
    Game Engine Architecture 3
    Game Engine Architecture 2
    补码
    工厂模式
    Game Engine Architecture 1
    YDWE Keynote
    3D Math Keynote 4
    3D Math Keynote 3
    3D Math Keynote 2
    OGRE中Any 类型的实现
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/9013126.html
Copyright © 2020-2023  润新知