javascript - 使用 $ 的变量声明

标签 javascript jquery

在 $ 的声明下方。是一个 javascript 变量吗?

我了解如何使用 $ 作为选择器

$('#Text').click(function () {
  $('#Text').css('color', 'red')
});

但是当我声明变量时,我习惯于将其声明为 var x = function(){}...

此符号表示“$”的含义。是声明变量的 jquery 方式吗?

$.searchTwitter= function(){


                    $.ajax({
                        url:"http://search.twitter.com/search.json",
                        data:{
                                q:'dogs'
                        },
                        dataType:'jsonp',
                        success:function(results){
                            console.log(results);
                        }
                    });
               };

 $.searchTwitter();

最佳答案

jQuery中,$jQuery的别名。

$.ajax();jQuery.ajax();

相同

Javascript 中,$ 没什么特别的;只是一个有效的 JavaScript 标识符。

引用:https://learn.jquery.com/about-jquery/how-jquery-works/

Note: The jQuery library exposes its methods and properties via two properties of the window object called jQuery and $. $ is simply an alias for jQuery and it's often employed because it's shorter and faster to write.

关于javascript - 使用 $ 的变量声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112191/

相关文章:

javascript - 使用 Javascript 生成高质量 PDF (jspdf+html2canvas)

javascript - 这两种加载javascript文件的优缺点?

javascript - 计算上传剩余时间

javascript - 为日期时间选择器设置 slider 的默认值

javascript - 没有鼠标悬停的 jQuery 悬停触发

Javascript将变量连接到url

jquery 在元素加载时加载图像

javascript - 获取类名整数(如果存在)

javascript - 查询对象数组javascript

Javascript 图像覆盖在 IE 中不起作用