zoukankan      html  css  js  c++  java
  • JQuery 基础

    $()下常用的方法:

    filter() : 过滤

    not():与过滤正好相反的方法

    has() :包含的意思

    filter方法与has方法的区别:

    filter方法和not方法针对的是当前元素

    而has看的是元素里面的东西

    比如:

    <script type="text/javascript" src="jquery-1.10.1.min.js"></script>
    <script>
    
    //has : 包含
    
    $(function(){
    
        //$('div').has('span').css('background','red');
        
        //$('div').has('.box').css('background','red');
        $('div').filter('.box').css('background','red');
        
    });
    
    
    
    </script>
    </head>
    
    <body>
    <div>div1<span class="box">span</span></div>
    <div class="box">div2</div>
    </body>

    next():下一个节点

    prev():上一个节点

    find(): 查找

    eq(): 类似于原生JS一组元素的下标

    index():索引就是当前元素在所有兄弟节点中的位置

    用原生JS和JQuery来实现选项卡功能:

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>JQuery选项卡</title>
    <style type="text/css">
        #div1 div { width: 200px; height: 200px; border: 1px red solid; display: none}
        .active { background: red}
    
    </style>
    <script src="jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
        // window.onload = function(){
    
        //     var oDiv = document.getElementById('div1');
        //     var aInput = oDiv.getElementsByTagName('input');
        //     var aCon = oDiv.getElementsByTagName('div');
    
        //     for(var i=0; i<aInput.length; i++){
    
        //         aInput[i].index = i;
    
        //         aInput[i].onclick = function(){
    
                    
        //             for(var i=0; i<aInput.length; i++){
     //                    aInput[i].className = '';
     //                    aCon[i].style.display = 'none';
    
        //             }
    
        //             this.className = 'active';
        //             aCon[this.index].style.display = 'block';
        //         }
        //     }
        // }
    
        $(function(){
    
            $('#div1').find('input').click(function(){
                $('#div1').find('input').attr('class','');
                $('#div1').find('div').css('display','none');
                $(this).attr('class','active');
                $('#div1').find('div').eq($(this).index()).css('display','block');
            })
        });
    </script>
    </head>
    
    <body>
    <div id="div1">
    
        <input class="active" type="button" value="1">
        <input type="button" value="2">
        <input type="button" value="3">
        <div style="display:block">111</div>
        <div>222</div>
        <div>333</div>
    
    </div>
    
    </body>
    </html>
  • 相关阅读:
    drupal drush 在windows下的安装和配置
    Drupal 7 配置ckeditor和ckfinder编辑器实现图片上传--不用wysisyg
    阿里云Centos配置iptables防火墙
    25个最常用的iptables策略
    防简单攻击iptables策略
    iptables防DDOS攻击和CC攻击设置
    Linux Web服务器网站故障分析常用的命令
    Linux/CentOS防CC攻击脚本
    Map字符串类型去掉空格处理
    读文件字节流大小的动态设置
  • 原文地址:https://www.cnblogs.com/zhangxg/p/4740818.html
Copyright © 2011-2022 走看看