Dzwebs.Net

撰写电脑技术杂文十余年

$与jquery

Admin | 2016-7-27 10:05:14 | 被阅次数 | 3230

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  我们在使用JS的时候,通常会遇到$与jquery这样的情况,那么,到底$与jquery之间有什么区别和联系吗?

  $是JQuery的别名 ,在使用上是一样的,两者可以互换位置。

  $==jQuery; //true

  $===jQuery; //true 

  $和jQuery 意义是一样的 一般情况用简写形式  $ jQuery  用在多JS框架并用的情况下 JS框架并用 需要用jQuery  一个函数转换一下。

  $和jQuery都是jquery框架的选择器,它两的意义是一样的。编写js代码时,程序员习惯自动以 var $=document.getElementById(id);再使用jquery框架时,为了避免$的冲突,通常也使用jQuery。

  下面我们来看看一个例子:

  jQuery.ajax(
    {    
        async: false,//false为同步请求
        url:"Common1.ashx",
        data:{Part1:1,Part2:"Two"},    
        type:"post",    
        cache:false,   
        //contentType: "application/json;charset=utf-8",
        dataType: "text",   
        success:function(Result)
        {    
            //alert(Result.split(",")[2]);
            MyGetData=Result;   
        },    
        error: function(xhr,status,error)
        {
            if (xhr == 'undefined' || xhr == undefined)
            {
                alert('undefined');
            }
            else
            {
                alert('object is there');
            }
            alert(status);
            alert(error);
        }   
    });

  上面的代码,完全等价于下面的代码

  $.ajax(
    {    
        async: false,//false为同步请求
        url:"Common1.ashx",
        data:{Part1:1,Part2:"Two"},    
        type:"post",    
        cache:false,   
        //contentType: "application/json;charset=utf-8",
        dataType: "text",   
        success:function(Result)
        {    
            //alert(Result.split(",")[2]);
            MyGetData=Result;   
        },    
        error: function(xhr,status,error)
        {
            if (xhr == 'undefined' || xhr == undefined)
            {
                alert('undefined');
            }
            else
            {
                alert('object is there');
            }
            alert(status);
            alert(error);
        }   
    });


该杂文来自: 网页制作杂文

上一篇:ajax dataType

下一篇:jquery ajax ashx示例

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计