设为首页 收藏本站
查看: 2060|回复: 0

[经验分享] python_day15_前端_jQuery

[复制链接]

尚未签到

发表于 2018-8-5 09:44:33 | 显示全部楼层 |阅读模式
  一 jQuery是什么?
  <1> jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team。
  <2>jQuery是继prototype之后又一个优秀的Javascript框架。其宗旨是——WRITE LESS,DO MORE!
  <3>它是轻量级的js库(压缩后只有21k) ,这是其它的js库所不及的,它兼容CSS3,还兼容各种浏览器
  <4>jQuery是一个快速的,简洁的javaScript库,使用户能更方便地处理HTMLdocuments、events、实现动画效果,并且方便地为网站提供AJAX交互。
  <5>jQuery还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。
  二 什么是jQuery对象?
  jQuery 对象就是通过jQuery包装DOM对象后产生的对象,jQuery 对象是 jQuery 独有的. 如果一个对象是 jQuery 对象, 那么它就可以使用 jQuery 里的方法: $(“#test”).html();
  基础语法:  jquery的基础语法:$(selector).action()
  三  jQuery引入方式
  下载地址:https://code.jquery.com/jquery-3.3.1.js,复制代码或者下载它,创建一个Jquery-xxxx.js文件,引入代码如下
<script src=&quot;jQuery_v3.3.1.js&quot;></script>  <script> 代码内容 </script>
  四 选择器和筛选器
  4.1 选择器
  4.1.1 基本选择器(4种 element(标签), *(全部), .(class) #(id) )  // element
  
      // $(&quot;p&quot;).css('color','red');
  
      // *
  
      // $(&quot;*&quot;).css('color','red');
  
      // . class
  
      // $('.i1').css('color','red');
  
      // # id
  
      $('#a1').css('color','red');
  

  
  4.1.2 层级选择器 (4种)
  
      $(&quot;.outer div&quot;)     后代选择器
  
      $(&quot;.outer>div&quot;)     子代选择器
  
      $(&quot;.outer+div&quot;)      毗邻选择器
  
      $(&quot;.outer~div&quot;)      最近标签毗邻选择器
  # 后代选择器
     <div class=&quot;div1&quot;> hello div1  
        <i class=&quot;i1&quot;>hello i</i><br>
  
        <div class=&quot;div2&quot;> hello div2</div>
  
    </div>
  

  
    <script src=&quot;jQuery_v3.3.1.js&quot;></script>
  
    <script>
  
        $(&quot;.div1 div&quot;).css('color','yellow');
  
    </script>
DSC0000.jpg

  # 子代选择器
<div class=&quot;div1&quot;> hello div1  
    <div class=&quot;div2&quot;>
  
        <p class=&quot;p&quot;>uuuuuuu</p>
  
    </div>
  
    <div class=&quot;div3&quot;> hello div2</div>
  
    <p class=&quot;p2&quot;>p22222</p>
  
</div>
  

  
<script src=&quot;jQuery_v3.3.1.js&quot;></script>
  
<script>
  
    $('div>p').css('color','blue')
  
</script>
DSC0001.jpg

  # 毗邻
<b class=&quot;b&quot;>毗邻</b>  
script中添加 $('div+b').css('font-size','20px')
DSC0002.jpg

  # 隔了一层或多层标签的邻居
<div> xxx</div>  
<p class=&quot;p3&quot;>p3p3</p>
  
<b class=&quot;b&quot;>毗邻</b>
  
script中添加  $('div~b').css('font-size','30px')
DSC0003.jpg

  4.1.3 基本筛选器
   $(&quot;li:first&quot;) $(&quot;li:last&quot;)  $(&quot;li:eq(2)&quot;)  $(&quot;li:even&quot;) $(&quot;li:gt(1)&quot;) $(&quot;li:lt(1)&quot;)<ul>  
    <li>1111</li>
  
    <li>2222</li>
  
    <li>3333</li>
  
    <li>4444</li>
  
    <li>5555</li>
  
</ul>
  // 第一个筛选器
$('li:first').css('font-size','20px');
DSC0004.jpg

  // 最后一个筛选器
$('li:last').css('font-size','20px');
DSC0005.jpg

  // 等于第几个筛选器 从第0下标开始 3就是第四个标签
$('li:eq(3)').css('font-size','20px');
DSC0006.jpg

  // 小于第几个筛选器
$('li:lt(3)').css('font-size','20px');
DSC0007.jpg

  // 大于第几个筛选器
        $('li:gt(3)').css('font-size','20px');
DSC0008.jpg

  4.1.4 属性选择器
  $('[id=&quot;div1&quot;]')   $('[&quot;xiong=&quot;xa&quot;][id]')
  <div class=&quot;div1&quot;>  
      <p class=&quot;p1&quot; xiong=&quot;xia&quot;>自定义属性</p>
  
      <p class=&quot;p1&quot; xiong=&quot;xi2a&quot;>自定义属性2</p>
  
  </div>
  

  
  <script src=&quot;jQuery_v3.3.1.js&quot;></script>
  <script>
  // 系统属性
$('[class=&quot;p1&quot;]').css('color','blue');
DSC0009.jpg

  // 自定义属性
$('[xiong=&quot;xia&quot;]').css('color','yellow');
DSC00010.jpg

  // 多个属性
$('[class=&quot;p1&quot;][xiong=&quot;xi2a&quot;]').css('color','blue');
DSC00011.jpg

  </script>
  4.1.5 表单选择器   $('[:text]')
<input type=&quot;text&quot; name=&quot;&quot; id=&quot;inp1&quot;>  
<input type=&quot;submit&quot;>
  // 这样的话就是属性选择器了
$('[type=&quot;text&quot;]').css('width','50px');
DSC00012.jpg

  // 表单选择器
$(':text').css('width','60px');
DSC00013.jpg

  4.1.6 选择器
children()//子代  find()//后代
  

  next()//下一个标签
  nextAll()//标签下面所有的
  nextUntil(&quot;#xx&quot;)  //直到找着id为xx的标签,但不包含xx
  

  prev()//上一个标签元素
  prevAll()//上一个标签所有元素
  preUntil('#xx')  // 直到找着上一个元素id为xx的标签或者class,但不包含xx
  

  parent()    //父级标签元素
  parents()//父级往上的所有标签元素
  parentUntil()//// 直到找着父级id为xx的标签或者class,但不包含xx
  

  siblings()//除了本身元素,周边所有元素都包含
  # 用法
    <div class=&quot;ccc&quot;>uuuuu</div>  
    <div class=&quot;ccc2&quot;>ccc3</div>
  

  
    <div class=&quot;firsts&quot;>
  
        <p class=&quot;twop&quot;>twop</p>
  
        <div class=&quot;twodiv&quot;>
  
            <p>threep</p>
  
            <div class=&quot;three&quot;>threediv</div>
  
        </div>
  
    </div>
  
    <div class=&quot;uuu&quot;>uuuuu</div>
  
    <div class=&quot;uu3u&quot;>uuuu3u</div>
  
    <p class=&quot;po&quot;>pp</p>
  

  
    <script src=&quot;jQuery_v3.3.1.js&quot;></script>
<!--子代选择-->  
$('.first').children().css('color','blue');
  

  
// 后代的div选择
  
$('.first').find('div').css('color','blue');
  

  
// 下一个标签
  
$('.firsts').next().css('color','blue');
  

  
// 下一个所有标签
  
$('.firsts').nextAll().css('color','blue');
  

  
//下一个选择的标签,不包含选择的标签
  
$('.firsts').nextUntil('.po').css('color','blue');
  

  
//上一个标签
  
$('.firsts').prev().css('color','blue');
  

  
// 上一个所有标签
  
$('.firsts').prevAll().css('color','blue');
  

  
//上一个选择的标签,不包含选择的标签
  
$('.firsts').prevUntil('.ccc').css('color','blue');
  

  
// 父级标签除了本身标签往上一层的标签都是父级
  
$('.three').parent().css('color','blue');
  

  
//父级往上的所有标签元素
  
$('.firsts .twodiv .three').parents('body').css('color','blue');
  

  
// 直到找着父级id为xx的标签或者class,但不包含xx
  
$('.firsts .twodiv .three').parentsUntil('body').css('color','blue');
  

  
//除了本身元素,周边所有元素都包含
  
$('.firsts').siblings().css('color','blue');
  4.1.7 操作属性
  // 固有属性建议用prop,自定义属性建议用attr
attr('值')//获取值内容  attr('值','内容')//设置值内容
  prop('值')//只能查找内置标签属性
  val('固有属性')//只能是固有属性才能被查找
  --------------------------HTML代码/文本/值
  
        $(&quot;&quot;).html([val|fn])
  
        $(&quot;&quot;).text([val|fn])
  
        $(&quot;&quot;).val([val|fn|arr])
  attr属性
<input type=&quot;checkbox&quot; class=&quot;inp&quot; checked>  
<input type=&quot;checkbox&quot; class=&quot;inp2&quot;>
  

  
<script src=&quot;jQuery_v3.3.1.js&quot;></script>
  
<script >
  
    console.log($(':checkbox').attr(&quot;checked&quot;))
  
    console.log($('.inp2').attr(&quot;checked&quot;))
  
</script>
DSC00014.jpg   # 当值没有定义时,会直接提示无定义而不是false

  prop 属性
        console.log($(':checkbox').prop(&quot;checked&quot;))  
        console.log($('.inp2').prop(&quot;checked&quot;))
DSC00015.jpg   // 有值显示true,没有直接false

//也可以直接设定值  attr 跟prop 都是 只有一个为查询,两个(第一个是对象,第二个是值)  
console.log($('.inp2').prop(&quot;checked&quot;,true))
  4.1.7 循环
    <table border=&quot;1px&quot;>  
        <tr>
  
            <th>111</th>
  
        </tr>
  
        <tr>
  
            <th>111</th>
  
        </tr>
  
        <tr>
  
            <th>111</th>
  
        </tr>
  

  
    </table>
  
<script src=&quot;jQuery_v3.3.1.js&quot;></script>;
  
    <script >
  
        a=[11,22,33];
  
        // x下标 Y值
  
        $.each(a,function (x,y) {
  
            console.log(x)
  
            console.log(y)
  
        })
  
        // 方式二,找着标签然后再进行循环
  
        $(a).each(function () {
  
            console.log(this)
  
        })
  
        $('th').each(function () {
  
             $(this).html('hello')
  
        })
  

  
    </script>
DSC00016.jpg DSC00017.jpg

  // 正反向练习
<div>  
    <input type=&quot;checkbox&quot;> 音乐
  
</div>
  
<div>
  
    <input type=&quot;checkbox&quot;> 美女
  
</div>
  
<div>
  
    <input type=&quot;checkbox&quot;> 爬山
  
</div>
  

  

  
<hr>
  
<button onclick=&quot;chioseAll()&quot;>全选</button>
  
<button onclick=&quot;clearAll()&quot;>取消</button>
  
<button onclick=&quot;invert()&quot;>反选</button>
  

  
<script src=&quot;jQuery_v3.3.1.js&quot;></script>
  
<script >
  
    // 循环列表,设定所有的checked都为 true
  
    function chioseAll() {
  
        $(&quot;:checkbox&quot;).each(function () {
  
            $(this).prop('checked',true)
  
        })
  
    }
  
    // 循环列表,设定所有的checked都为false
  
    function clearAll() {
  
        $(&quot;:checkbox&quot;).each(function () {
  
            $(this).prop('checked',false)
  
        })
  
    }
  
    function invert() {
  
        // 循环列表,当checked等于true的时候其它元素都为false
  
        $(&quot;:checkbox&quot;).each(function () {
  
            if($(this).prop('checked')){
  
                $(this).prop('checked',false)
  
            }else {
  
                $(this).prop('checked',true)
  
                console.log(this)
  
            }
  
        })
  
    }
  

  
</script>
  4.1.8 增删改
  注意:新加的值每次都需要加$
//内部插入  
    $(&quot;&quot;).append(content|fn)      ----->$(&quot;p&quot;).append(&quot;<b>Hello</b>&quot;);
  
    $(&quot;&quot;).appendTo(content)       ----->$(&quot;p&quot;).appendTo(&quot;div&quot;);
  
    $(&quot;&quot;).prepend(content|fn)     ----->$(&quot;p&quot;).prepend(&quot;<b>Hello</b>&quot;);
  
    $(&quot;&quot;).prependTo(content)      ----->$(&quot;p&quot;).prependTo(&quot;#foo&quot;);
  

  
//外部插入
  
    $(&quot;&quot;).after(content|fn)       ----->$(&quot;p&quot;).after(&quot;<b>Hello</b>&quot;);
  
    $(&quot;&quot;).before(content|fn)      ----->$(&quot;p&quot;).before(&quot;<b>Hello</b>&quot;);
  
    $(&quot;&quot;).insertAfter(content)    ----->$(&quot;p&quot;).insertAfter(&quot;#foo&quot;);
  
    $(&quot;&quot;).insertBefore(content)   ----->$(&quot;p&quot;).insertBefore(&quot;#foo&quot;);
  

  
//替换
  
    $('h1').replaceWith($ele)
  

  
//删除
  
    $(&quot;.increase&quot;).empty()
  
    $(&quot;.increase&quot;).remove()
  
//克隆
  
        var $ele2=$(&quot;.increase&quot;).clone()
  
        $(&quot;.increase&quot;).after($ele2)
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>增删改</title>
  
</head>
  
<body>
  
    <div class=&quot;increase&quot;>
  
        <h1>hello world</h1>
  
    </div>
  

  
    <button onclick=&quot;add()&quot;>增加</button>
  

  
    <script src=&quot;jQuery-3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        function add() {
  
                // 方法都放下边
  
        }
  
    </script>
  
</body>
  
</html>
  增加  在已有内联标签的下边
// 方法一: 直接添加  
// $(&quot;.increase&quot;).append(&quot;<h1> hello world </h1>&quot;)
  

  
//方法二
  
var $ele=$(&quot;<h1>&quot;)
  
$ele.html(&quot;hello world&quot;)
  

  
$(&quot;.increase&quot;).append($ele)     // 键放前面,值放后边
  

  
$ele.appendTo(&quot;.increase&quot;)      // 值放在前面,键放后边
DSC00018.jpg    每点一次增加 会加一个标签

  增加  在已有内联标签的上边
// $(&quot;.increase&quot;).prepend($ele)  
$ele.prependTo(&quot;.increase&quot;)
DSC00019.jpg

  增加  在已有块联标签的下边  在标签外
// $(&quot;.increase&quot;).after($ele)  
$ele.insertAfter(&quot;.increase&quot;)
DSC00020.jpg

  增加  在已有块联标签的上边  在标签外
// $(&quot;.increase&quot;).before($ele)  
$ele.insertBefore(&quot;.increase&quot;)
DSC00021.jpg

  替换
$('h1').replaceWith($ele)
DSC00022.jpg

  删除   清空标签内的所有内容
$(&quot;.increase&quot;).empty()
DSC00023.jpg

  删除   直接删除标签
$(&quot;.increase&quot;).remove()
DSC00024.jpg

  克隆
// 这种方式有问题,每次复制都会全部复制  
var $ele2=$(&quot;.increase&quot;).clone()
  
$(&quot;.increase&quot;).after($ele2)
  // 增加删除框
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>复制框</title>
  
</head>
  
<body>
  
    <div class=&quot;context&quot;>
  
        <div class=&quot;item&quot;>
  
            <button onclick=&quot;add(this)&quot;>+</button>
  
            <input type=&quot;text&quot;>
  
        </div>
  
    </div>
  

  
    <script src=&quot;jQuery-3.3.1.js&quot;></script>
  
    <script>
  
        function add(self) {
  
            //复制到最上一级标签
  
                       $ele2=$(self).parent().clone();
  
            //找着button标签修改+号为-号并修改事件为remove
  
                       $ele2.children('button').html('-').attr('onclick','remove(this)');
  
            $('.context').after($ele2)
  
        }
  
        function remove(self) {
  
            // 只做删除操作
  
$(self).parent().remove()
  
        }
  
    </script>
  
</body>
  
</html>
  4.1.9 css操作
CSS  
        $(&quot;&quot;).css(name|pro|[,val|fn])
  
    位置
  
        $(&quot;&quot;).offset([coordinates])
  
        $(&quot;&quot;).position()
  
        $(&quot;&quot;).scrollTop([val])
  
        $(&quot;&quot;).scrollLeft([val])
  
    尺寸
  
        $(&quot;&quot;).height([val|fn])
  
        $(&quot;&quot;).width([val|fn])
  
        $(&quot;&quot;).innerHeight()
  
        $(&quot;&quot;).innerWidth()
  
        $(&quot;&quot;).outerHeight([soptions])
  
        $(&quot;&quot;).outerWidth([options])
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>css操作</title>
  
    <style>
  
        *{
  
            margin: 0px;
  
            padding: 0px;
  
        }
  
        .up,.down{
  
            width: 100px;
  
            height: 200px;
  
        }
  
        .up{
  
            background-color: #ccdcef;
  
        }
  
        .down{
  
            background-color: #cccccc;
  
        }
  
    </style>
  
</head>
  
<body>
  
    <div class=&quot;up&quot;></div>
  
    <div class=&quot;down&quot;></div>
  

  
    <script src=&quot;jQuery_v3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script >
  
        //方法单列
  
    </script>
  
</body>
  
</html>
  offset
//以body做为夭口的偏移量  
console.log($(&quot;.up&quot;).offset().top);
  
console.log($(&quot;.up&quot;).offset().left);
  

  
console.log('down: '+$(&quot;.down&quot;).offset().top);
  
console.log('donw: '+$(&quot;.down&quot;).offset().left);
DSC00025.jpg

  position
// 相对于已经定位的父标签的偏移量  

  
//给down增加一层测试position偏移量  js中增加 .donw_f {position: absolute;}
  
<div class=&quot;donw_f&quot;>
  
    <div class=&quot;down&quot;></div>
  
</div>
  

  
console.log($(&quot;.up&quot;).position().top);
  
console.log($(&quot;.up&quot;).position().left);
  

  
console.log($(&quot;.down&quot;).position().top);
  
console.log($(&quot;.down&quot;).position().left);
DSC00026.jpg    以position做为偏移量,down的porision参照物是它的父级,所以也就是直接为0,如果是以body那就是200

  height widht
// 高度height  
console.log($('.up').height());
  
console.log($('.down').height());
  

  
// 宽度widht
  
console.log($(&quot;.up&quot;).width());
  
console.log($(&quot;.down&quot;).width());
DSC00027.jpg

innerHeight , outerHeight , outerHeight.up{  
    border: 3px solid red;
  
    padding: 4px;
  
    margin: 2px;
  
    background-color: #ccdcef;
  
}
  

  
//包含padding值大小
  
console.log('innerHeight: '+$(&quot;.up&quot;).innerHeight());
  

  
//包含padding跟border值大小
  
console.log('outerHeight: '+$(&quot;.up&quot;).outerHeight());
  

  
// 包含 padding , border与 margin 外边界的大小
  
console.log('outerHeight: '+$(&quot;.up&quot;).outerHeight(true));
DSC00028.jpg    // 高度计算

scrollTop  
    //获取下拉框位置并返回顶部
  

  
<!DOCTYPE html>
  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>returnTop</title>
  
    <style>
  
        *{
  
            margin: 0px;
  
            padding: 0px;
  
        }
  
        .up,.down{
  
            width: 100%;
  
            height: 1300px;
  
        }
  
        .down{
  
            background-color: #cccccc;
  
        }
  
        .rtop{
  
            position: fixed;
  
            right: 20px;
  
            bottom: 20px;
  
            padding: 3px;
  
            height: 30px;
  
            width: 70px;
  
            background-color: wheat;
  
            color: #b4b4b4;
  
            margin: 0 auto;
  
        }
  
        .hide{
  
            display: none;
  
        }
  
    </style>
  

  
</head>
  
<body>
  

  
    <div class=&quot;up&quot;></div>
  
    <div class=&quot;down&quot;></div>
  
    <div class=&quot;rtop hide&quot; onclick=&quot;backTop()&quot;>
  
        <div >返回顶部</div>
  
    </div>
  

  
    <script src=&quot;jQuery_v3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script >
  
        window.onscroll=function () {
  
            console.log($(window).scrollTop());
  
            // 获取鼠标上下拉的位置
  
            $Back=$(window).scrollTop();
  
            // 当下拉框大于或等于200的时候移除hide显示窗体
  
            if ($Back >= 200 ){
  
                $(&quot;.rtop&quot;).removeClass('hide');
  
            //小于200那么就在给它加上hide 隐藏窗体
  
            }else {
  
                $(&quot;.rtop&quot;).addClass('hide');
  
            }
  
        }
  
        // 当鼠标点击时 scrollTop定义为0返回最上头
  
        function backTop() {
  
            $(window).scrollTop(0);
  
        }
  
    </script>
  
</body>
  
</html>
  4.1.10 事件
// 页面载入 方式一  
$(document).ready(function () {
  
    内容
  
})
  

  
// 页面载入 方式二
  
$(function() ){
  内容
  
}
  

  
// 点击事件    [标签,.属性,#id].click(function())
  
('ul').click(function () {
  内容
  
})
  

  
// 点击事件无法使用  [标签,.属性,#id].bind( 'click',function() ){ 内容 }
  
$('ul li').bind('click',function () {
  
    alert(123)
  
})
  

  
// 临时点击事件,每次点击的时候会重新从这里查找
  
$('ul').on('click','li',function () {}
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>事件</title>
  

  

  
    <script src=&quot;jQuery_v3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        // <!--页面载入 方式一-->
  
        // $(document).ready(function () {
  
        //     $('ul li').click(function () {
  
        //         alert(123);
  
        //     });
  
        // });
  
        // <!--页面载入 方式二-->
  
               $(function () {
  
            $('ul li').click(function () {
  
                alert(123);
  
            });
  

  
        })
  
    </script>
  
</head>
  
<body>
  
    <ul>
  
        <li>111</li>
  
        <li>222</li>
  
        <li>333</li>
  
    </ul>
  
    <button>增加</button>
  
    <!--<script src=&quot;jQuery_v3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script >
  
        // 点击增加以及事件都能使用
  
        // $('ul').click(function () {
  
        //     alert(123);
  
        // })
  

  
        // 点击事件无法使用
  
        // $('ul li').bind('click',function () {
  
        //     alert(123)
  
        // })
  

  
        // 临时点击事件,每次点击的时候会重新从这里查找.
  
        $('ul').on('click','li',function () {
  
            alert(123);
  
        });
  

  
        $('button').click(function () {
  
            $ele = $('<li>');
  
            var len=$('ul li').length;
  
            $ele.html((len+1)*111);
  
            $('ul').append($ele);
  
        });
  
    </script>-->
  

  
</body>
  
</html>
  5 动画效果
  5.1:显示隐藏
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>动画1</title>
  
    <style>
  
        .showItem{
  
            width: 100%;
  
            height: 100px;
  
            background-color: beige;
  
            vertical-align: bottom;
  
            text-align: center;
  
        }
  
    </style>
  
    <script src=&quot;jquery-3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        //方式一
  
//        $(document).ready(function () {
  
//
  
//        })
  
        // 方式二
  
     $(function () {
  
            // 显示这个标签栏
  
             $('.show').click(function () {
  
                $(&quot;.showItem&quot;).show(1000);
  
            });
  

  
            // 隐藏这个标签栏
  
             $('.hide').click(function () {
  
                $(&quot;.showItem&quot;).hide(1000);
  
            });
  
            // 如果是隐藏,那么点击是显示,反之亦常
  
             $('.toggle').click(function () {
  
                $(&quot;.showItem&quot;).toggle(1000);
  
            })
  

  
        })
  
    </script>
  
</head>
  
<body>
  
    <div class=&quot;showItem&quot;>hello world</div>
  
    <button class=&quot;show&quot;>显示</button>
  
    <button class=&quot;hide&quot;>隐藏</button>
  
    <button class=&quot;toggle&quot;>切换</button>
  
</body>
  
</html>
  5.2 滑入滑出
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>动画2</title>
  
    <style>
  
        .move{
  
            width: 100%;
  
            height: 100px;
  
            text-align: center;
  
            background-color: aqua;
  
            margin-bottom: 3px;
  
        }
  
    </style>
  

  
    <script src=&quot;jquery-3.3.1.js&quot; type=&quot;text/javascript&quot;> </script>
  
    <script>
  
        $(document).ready(function () {
  
            // 往上隐藏
  
                 $('.show').click(function () {
  
                $('.move').slideUp();
  
            });
  
            // 隐藏后出现
  
                 $('.hide').click(function () {
  
                $('.move').slideDown();
  
            });
  
            // 集合了上面两种功能
  
                 $('.toggle').click(function () {
  
                $('.move').slideToggle();
  
            });
  
        })
  
    </script>
  
</head>
  
<body>
  
    <div class=&quot;move&quot;>hello world</div>
  
    <button class=&quot;show&quot;>往上隐藏</button>
  
    <button class=&quot;hide&quot;>往下出现</button>
  
    <button class=&quot;toggle&quot;>切换</button>
  
</body>
  
</html>
  5.3 淡入淡出
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>动画3</title>
  
    <style>
  
        .window{
  
            height: 100px;
  
            width: 100px;
  
            background-color: burlywood;
  
            margin-bottom: 10px;
  
        }
  
    </style>
  
    <script src=&quot;jquery-3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        $(function () {
  
            // 淡出效果 显示
  
         $('.in').bind('click',function () {
  
                $(&quot;.window&quot;).fadeIn(1000);
  
            });
  
            // 淡入效果 隐藏
  
         $('.out').bind('click',function () {
  
                $(&quot;.window&quot;).fadeOut(1000);
  
            });
  
            // 以上两种功能都包含, 淡入淡出效果
  
             $('.toggle').bind('click',function () {
  
                $(&quot;.window&quot;).fadeToggle(1000);
  
            });
  
            // 点击之后 1000是时间,0.4为透明的效果
  
                 $(&quot;.to&quot;).bind('click',function () {
  
                $(&quot;.window&quot;).fadeTo(1000,0.4);
  
            })
  
        })
  
    </script>
  
</head>
  
<body>
  
    <div class=&quot;window&quot;></div>
  
    <button class=&quot;in&quot;>in</button>
  
    <button class=&quot;out&quot;>out</button>
  
    <button class=&quot;toggle&quot;>toggle</button>
  
    <button class=&quot;to&quot;>to</button>
  
</body>
  
</html>
  5.4 回调函数
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>回调函数</title>
  
    <style>
  
        .window_yellow,.window_blue{
  
            width: 200px;
  
            height: 200px;
  
            margin-bottom: 10px;
  
            position: fixed;
  
        }
  
        .window_yellow{
  
            background-color: yellow;
  
        }
  
        .window_blue{
  
            background-color: blue;
  
            display: none;
  
        }
  
        .start{
  
            position: absolute;
  
            margin-top: 200px;
  
        }
  
    </style>
  
    <script src=&quot;jquery-3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        $(document).ready(function () {
  
            // 点击事件执行windows_yellow的Hide方法
  
$(&quot;.start&quot;).click(function () {
  
                // 回调函数最后再执行一次函数,
  
$('.window_yellow').hide(function () {
  
                    $('.window_blue').show()
  
                });
  
            });
  
        })
  

  
    </script>
  
</head>
  
<body>
  
    <div class=&quot;window_yellow&quot;></div>
  
    <div class=&quot;window_blue&quot;></div>
  
    <button class=&quot;start&quot;>start</button>
  
</body>
  
</html>
  5.5 插件
<!DOCTYPE html>  
<html lang=&quot;en&quot;>
  
<head>
  
    <meta charset=&quot;UTF-8&quot;>
  
    <title>扩展</title>
  
    <script src=&quot;jquery-3.3.1.js&quot; type=&quot;text/javascript&quot;></script>
  
    <script>
  
        //自定义语法一
  
//        $.extend({
  
//            //语法 属性名:function()
  
//            myFunc:function () {
  
//                console.log('hello')
  
//            }
  
//        });
  
//
  
//        $.myFunc();
  

  
        //自定义语法二  (有问题,结果怎么弄怎么不对)
  
         $.fn.extend({
  
           &quot;twoFunc&quot;:function () {
  
               for (var i=0;i<this.length;i++){
  
                   console.log(this.innerHTML)
  
               }
  
           }
  
        });
  
        $(&quot;p&quot;).twoFunc()
  

  
    </script>
  
</head>
  
<body>
  
    <p>hello 11</p>
  
    <p>hello 22</p>
  
</body>
  
</html>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-546837-1-1.html 上篇帖子: Python练手,样本 下篇帖子: 利用Python生成随机4位验证码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表