zoukankan      html  css  js  c++  java
  • jQurey学习

      API.jQuery 

    1.方法备忘

      8-1

    $(document).ready( foo );
    
    jQurey.noConflict();        //避免冲突
    
    $().bind( 'click' , click_foo );
    $().unbind('click');
    
    $(this).addClass( 'name' ).removeClass( 'name' );  	//jquery连缀
    
    $().toggle('slow', foo);	//new method using in 1.9.1, changing 'display'
    $().hover(foo1, foo2);
    
    keyup/keydown/keypress
    String.fromCharCode( event.keyCode )
    
    $().trigger('click');	//模拟用户事件、
    
    $().css('pro',val);
    $().css({'pro1':val1, 'pro2':val2});
    
    $().show().hide().fadeIn().fadeOut();  	//can add time in ()
    
    $().is('button');	//判断元素
    $().animate(css, speed, easing, foo);
    $().outWidth();
    $().each( function(){ $(this).attr = ''; });
    
    $('<a href="#">link</a>');	//创建元素
    = $.parseHTML('<a href="#">link</a>');

    $(el).find('li');    //返回选择元素列表
    $(el).children('li');
    = $( "li", el);

     The delegate() method attaches one or more event handlers for specified elements that are children of selected elements, and specifies a function to run when the events occur.

          $( "table" ).delegate( "td", "click", function() {        //jQuery1.4.3+  
        $( this ).toggleClass( "chosen" );
      });
    
      $( "table" ).on( "click", "td", function() {      //jQuery 1.7+
        $( this ).toggleClass( "chosen" );
      });     
    

      .data() Store arbitrary data associated with the matched elements

    $('p').data("x","p first");		
    $('p:first').text($('p').data("x"));
            //改变属性值
    	$('div.chapter a').attr({'rel':'external'});
    	$('div.chapter a[href*=wikipedia]').each(function(index){
    		$(this).attr({
    			'rel':'external',
    			'id' :'wiki_link_'+index
    		});
    	});
    
    	//插入
    	$(el_a).insertAfter(el_b);
    	$(el_b).after(el_a);
    	.insertBefore();
    	.before();
    
    	//加入子节点
    	$(el_child).prependTo(el_parent);
    	.prepend();
    	.append();
    	.appendTo();
    
    	.wrap();
    	.wrapAll();
    	.wrapInner();
    
    	.clone();
    
    	.html();
    	.text();
    	.replaceAll();
    	.replaceWith();
    
    	.empty();
    	.remove();
    

    两种each

    $.each(collection, callback_foo(index,val){}); 
    //collection can be array[1,2], object{'a':1,'b':2}
    
    $(el).each( funciton(index,val){});
    
    .filter()
    //add foo
    $('li').filter(function(index) {
    return index % 3 == 2;
    }).css('background-color', 'red');
    //select
    $("div")..filter(".middle").css("background", "#c8ebcc");
    $('li').filter(':even');
    

    AJAX

    jQuery.get( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

    $.load("xx.html");

    $.post()

     
    $('<div id="loading">Loading</div>')
    			.insertBefore('#targetEle')
    			.ajaxStart(function(){
    				$(this).show();
    			}).ajaxStop(function(){
    				$(this).hide();
    			});
    

     $(el,callback());

    2.jQuery插件

        jQuery插件的写法

        深入理解jQuery插件开发

    3.树状组件封装格式

    $.fn.GMVin = function(config){
      var GMVin = {
        detailParam: {},
        initData: function(data){},
        genLabelContent: function(info){},
        genLeftLabel: function(list, ren, colors){},
        genRightLabel: function(list, ren, colors){},
        genCenterLabel: function(list, ren, colors){},
        genLeftLine: function(ren, colors){},
        genRightLine: function(ren, colors){},
      };
      var chart = new Highcharts.Chart({..});
      return chart;
    }
    

      

    我相信,会有一个公正而深刻的认识来为我们总结的:那时,我们这一代独有的奋斗、思索、烙印和选择才会显露其意义。 ——《北方的河》

    博文来源:http://www.cnblogs.com/liaopr

    如果您觉得本文的内容对您的学习有所帮助,可以选择打赏我一杯咖啡:D

  • 相关阅读:
    Win10 VirtualBox 安装 OpenWrt/LEDE
    在华为云、腾讯云服务器中部署 Hadoop 集群
    记一次部署Hadoop后遭受kthreaddi挖矿病毒
    四种基本编程命名法
    词云图制作
    在Ubuntu18.04lts下安装NS2(含nam)
    二叉树的建立与遍历
    国内pip镜像
    java高斯消元模板
    图的3种储存方式
  • 原文地址:https://www.cnblogs.com/liaopr/p/3231768.html
Copyright © 2011-2022 走看看