zoukankan      html  css  js  c++  java
  • 解决jquery与其他库的冲突

    1、jquery在其他库之后导入

    第一种:
    jQuery.noConflict();//将变量$的控制权限交给其他类库,即将$的控制权让渡给其他类库
    jQuery(function(){
      jQuery("p").click(function(){
        alert(jQuery(this).text());
      });
    });
    $("p").style.display = "none";//其他类库照常使用$符
    
    第二种:
    var $j = jQuery.noConflict();//自定义一种快捷方式
    $j(function(){
      $j("p").click(function(){
            alert($j(this).text());
       });
    });
    $("p").style.display = "none";//其他类库照常使用$符

    如果不想使用jquery自定义备用名称(即前两种方法),又想使用$符,其避免与其他库冲突

    第三种:
     jQuery.noConflict();
     jQuery(function($){
        $("p").click(function(){
             alert($(this).text());
        });
     });
    $("p").style.display = "none";//其他类库照常使用$符
    
    第四种:
     jQuery.noConflict();
     (function($){
          $function(){
              $("p").click(function(){
                   alert($(this).text());
              });
          }
     });

    2、jQuery库在其他库之前导入(无需调用jQuery.noConflict()函数,可直接用”jQuery”来做一些jQuery的工作)

    jQuery(function(){
      jQuery("p").click(function(){
        alert(jQuery(this).text());
      });
    });
    $("p").style.display = "none";//其他类库照常使用$符
  • 相关阅读:
    python+selenium环境搭建以及遇到的坑
    (二)第一个测试用例
    (一)TestNG介绍与安装
    Appium详解server capabilities
    Mac安装MySQL数据库
    POI 设置单元格样式
    JAVA_HOME环境变量失效的解决办法
    svn linux 命令
    StringUtils工具类的常用方法
    ArrayUtils 方法
  • 原文地址:https://www.cnblogs.com/wanghaokun/p/6104131.html
Copyright © 2011-2022 走看看