美文网首页
jquery选择器

jquery选择器

作者: f6d8ee519880 | 来源:发表于2018-11-07 18:25 被阅读0次

面向对象

  • 面向过程与面向对象编程

1、面向过程:所有的工作都是现写现用。
2、面向对象:是一种编程思想,许多功能事先已经编写好了,在使用时,只需要关注功能的运用,而不需要这个功能的具体实现过程。

  • javascript对象

将相关的变量和函数组合成一个整体,这个整体叫做对象,对象中的变量叫做属性,变量中的函数叫做方法。javascript中的对象类似字典。

  • 创建对象的方法
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单体创建对象</title>
    <script type="text/javascript">
        var Tom = {
            // 属性
            name:'tom',
            age:18,

            // 方法
            showName:function(){
                alert(this.name);
            },
            showAge:function(){
                alert(this.age);
            }
        }

        //调用属性
        alert(Tom.name);
        alert(Tom.age);
        
        //调用方法
        Tom.showName();
    </script>
</head>
<body>
    
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工厂模式创建对象</title>
    <script type="text/javascript">
        function Person(name,age,job){
            //创建一个空对象
            // var o = new Object();//方式一
            var o = {};//方式二

            o.name = name;
            o.age = age;
            o.job = job;

            o.showName = function(){
                alert(this.name);
            }
            o.showAge = function(){
                alert(this.age);
            }
            o.showJob = function(){
                alert(this.job);
            }

            return o;
        }

        var Tom = Person('tom',18,'程序员');
        Tom.showJob();

        var Jack = Person('jack',19,'工程师');
        Jack.showJob();
    </script>
</head>
<body>
    
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>构造函数</title>
    <script type="text/javascript">
        function Person(name,age,job){
            this.name = name;
            this.age = age;
            this.job = job;

            this.showName = function(){
                alert(this.name);
            }
            this.showAge = function(){
                alert(this.age);
            }
            this.showJob = function(){
                alert(this.job);
            }
        }

        //new的作用就相当于工厂模式中最开始创建了一个空对象,最后把对象返回
        var Bob = new Person('bob',18,'产品');
        Bob.showJob();

        var Alex = new Person('alex',19,'运营');
        Alex.showJob();

        alert(Bob.showName == Alex.showName);//false
    </script>
</head>
<body>
    
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型模式</title>
    <script type="text/javascript">
        function Person(name,age,job){
            this.name = name;
            this.age = age;
            this.job = job;

            Person.prototype.showName = function(){
                alert(this.name);
            }
            Person.prototype.showAge = function(){
                alert(this.age);
            }
            Person.prototype.showJob = function(){
                alert(this.job);
            }
        }

        //先去自己的对象中找showName函数,再去构造函数的原型找
        var Lucy = new Person('lucy',18,'测试员');
        //重写自身对象中的方法,不会影响其它对象
        Lucy.showName = function(){
            alert('我的名字是' + this.name);
        }
        Lucy.showName();//我的名字是lucy

        var Lily = new Person('lily',19,'市场员');
        Lily.showName();//lily

        alert(Lucy.showName == Lily.showName);//false
    </script>
</head>
<body>
    
</body>
</html>

jQuery选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery选择器</title>
    <style type="text/css">
        #div1{
            color: red;
        }
        .box{
            color: green;
        }
        .list li{
            margin-bottom: 10px;
        }
    </style>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function(){
            //选择元素的规则和css样式相同
            $('#div1').css({color: 'pink'});
            $('.box').css({fontSize: '30px'});
            $('.list li').css({
                background: 'green',
                color: '#fff',
                fontSize: '20px',
                marginBottom: '10px'
            });
        })
    </script>
</head>
<body>
    <div id="div1">这是一个div元素</div>
    <div class="box">这是第二个div元素</div>
    <ul class="list">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ul>
</body>
</html>

相关文章

  • jquery选择器书目录

    jquery选择器-基本选择器 jquery选择器-层级选择器 jquery选择器-基本过滤选择器 jquery选...

  • JQUERY一

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器 jQuery 事件 jQuery...

  • jQuser有选择器

    jQuery基本选择器 jQuery过滤选择器 jQuery层级选择器 jQuery筛选选择器(方法)

  • 选择器

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器

  • jQuery 基础

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • jQuery

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • jQuery选择器

    一、jQuery常用选择器 二、jQuery选择器优势 三、jQuery常用基本选择器 四、jQuery常用层次选...

  • JQuery基础知识

    jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样式 css操作...

  • jQuery相关知识

    1、什么是jQuery选择器? jQuery选择器

  • jQuery选择器

    jQuery选择器 jQuery选择器完全继承了CSS的风格。学会使用选择器是学习jQuery的基础,jQuery...

网友评论

      本文标题:jquery选择器

      本文链接:https://www.haomeiwen.com/subject/kktbxqtx.html