zoukankan      html  css  js  c++  java
  • jQuery基础 --- 4.5日学习日记

    www.jquery.com

    JQ写法
       方法函数化
       链式操作
       取值赋值合体

    $()下的常用方法
      has()
      not()
      filter()
      next()
      prev()
      find()
      eq()
      index()
      attr()

    1,filter()的反义词not()

      filter()过滤 这个div 或者数据是 含有 class=“xxx” 的元素

      not()则相反

    2,filter()和has()去区别

      filter() 针对元素自身

      has() 针对元素里面的东西,有没有包含某元素

      filter()和not() 强调这个元素,而 has() 强调这个 元素里面的 东西,里面有没有包含某个元素

    $()下的常用方法


    addClass()   removeClass()  添加样式
    width()   innerWidth()   outerWidth()
    insertBefore()  before()
    insertAfter()   after()
    appendTo()   append()
    prependTo()   prepend()
    remove()
    on()  off()
    scrollTop()

    1,addClass()   removeClass()  用法

    用法:<script>
    $(function(){
    
    	$('div').addClass('box2 box4');  //在div中添加元素
    	$('div').removeClass('box1');  //在div中删除元素
    	
    });
    </script>
    </head>
    <body>
    <div class="box1 box2">div</div>
    </body>
    </html>

    2,width()   innerWidth()   outerWidth() 用法和区别

    用法:$(function(){
    
    	alert( $('div').width() );  //width
    	
    	alert( $('div').innerWidth() );  //width + padding
    	
    	alert( $('div').outerWidth() );  //width + padding + border
    	
    	alert( $('div').outerWidth(true) );  //width + padding + border + margin
    	
    });

    3,insertBefore()  before() 区别

    //区别 :后续操作变了
    	
    	//$('span').insertBefore( $('div') ).css('background','red');
    	
    	$('div').before( $('span') ).css('background','red');

    4,on()  off() 及 scrollTop()

    on()  off() 监听鼠标 动作 和 消失 on()可以 监听鼠标 移入 和 点击事件

    用法:$(function(){ /*$('div').click(function(){ alert(123); });*/ /*$('div').on('click',function(){ alert(123); });*/ /*$('div').on('click mouseover',function(){ alert(123); });*/ /*$('div').on({ 'click' : function(){ alert(123); }, 'mouseover' : function(){ alert(456); } });*/ $('div').on('click mouseover',function(){ alert(123); $('div').off('mouseover'); }); });
    
    
    scrollTop() : 滚动距离
    用法: $(function(){
    
    	$(document).click(function(){
    		
    		alert( $(window).scrollTop() );  //滚动距离
    		
    	});
    	
    });
    jquery  中 $ 富豪 创建 标签  一定要加上 < >  尖括号,否则为 选择元素


  • 相关阅读:
    预防新型冠状病毒科普宣传网站
    四则运算
    结对审查
    最大子段和
    单元自动测试Junit
    浅谈过去,畅想未来
    第一次的结对编程
    代码审查
    单元测试
    junit4单元测试
  • 原文地址:https://www.cnblogs.com/dh2608/p/5355932.html
Copyright © 2011-2022 走看看