美文网首页
2018-09-29

2018-09-29

作者: 金政锐 | 来源:发表于2018-09-29 08:14 被阅读0次

闭包存循环索引

window.onload =function(){vara =document.getElementsByTagName("li");// alert(a.length)for(vari =0; i < a.length; i++) {                (function(i){                    a[i].onclick =function(){                        alert(i)                    }                })(i)            }        }//如果直接写不用闭包则结果会循环很快,结果只会是最后一个值

面向对象

单体创建对象

varTom = {name:'tom',age:18,showname:function(){                alert('我的名字叫'+this.name);            },showage:function(){                alert('我今年'+this.age +'岁');            }        }        Tom.showage();        alert(Tom.age)

工厂模式

functionPerson(name, age, job){varo =newObject();            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);            };returno;//必须有return}vartom = Person('tom',18,'程序员');//直接调用函数alert(tom.job)        tom.showname();

构造函数

functionPerson(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)            }//不必须有return}varjack =newPerson("jack",22,"攻城狮");//实例化注意和面向对象中工厂的区别// var tom = new Person('tom', 22, '程序员');// jack.showjob()// alert(jack.name==tom.name)functionaa(a,b){            alert(this+" "+a+" "+b)        }        aa(1,2)        aa.call("abf",1,2)//更改this值aa.apply("abf",[2,3])//更改this值

继承

functionFather(name, age){this.name = name;this.age = age;        }        Father.prototype.showname =function(){            alert(this.name)        };        Father.prototype.showage =function(){            alert(this.age)        };//子类functionSon(name, age, job){            Father.call(this, name, age);//属性继承this.job = job        }//方法继承Son.prototype=newFather();        Son.prototype.showjob =function(){            alert(this.job)        };varjack =newSon("jack",18,'程序猿');        jack.showname();        jack.showage();        jack.showjob();//不必须有return

jQuery部分选择器

$("#div1").next().css({//下一个元素color:'red'})    $("#div1").nextAll().css({//也可以选择特定的元素如:$("#div1").nextAll('p')background:'aqua'})    $("#span1").parent().css({width:'100px',backgroundColor:'red',fontSize:'30px'})    $("#two").closest('div').css({//祖先background:'gold'})    $(".list").children().css({background:'green'})    .end().css({background:'red'})    $(".list2 li:eq(2)").css({background:'black'})    .siblings().css({//选择同级兄弟元素background:'red'})    $(".div2").find("#link1").css({background:'gold'})

增删样式

// alert($(".box1").css('font-size'))$(".box1").css({background:'gold'})    $(".box1").addClass('big')    $(".box1").removeClass('box1')

点击事件

$(function(){            $("#btn").click(function(){                $(".box1").toggleClass('sty')//切换样式})        })

获取索引值

$("#list li").click(function(){// alert(this.innerHTML)// alert($(this).html())//和上面一样都是获取值alert($(this).index())//获取索引值})

相关文章

  • 2018-09-29

    2018-09-29 2018-09-29 2018-09-29 【日精进打卡第0049天:元气满满】 王航~立心...

  • 2018-09-29

    2018-09-29 2018-09-29 【日精进打卡第0048天:元气满满】 王航~立心小学部 【知~学习:名...

  • Linux Basic Command

    UpDate 2018-09-29 1538230612Author unnam3dMail indv.zhang...

  • 模仿jQuery实现一个API

    title: 模仿jQuery实现一个APIdate: 2018-09-29 16:46:48tags: [Jav...

  • 照片

    鹭说:“狗仔又来了,快跑吧!” 鸭子说:“别理她!我们继续玩。” 2018-09-29 心地

  • (转)栀子花开呀开……

    《秋天的雨》教学反思 聆听栀子花开 互相关注 2018-09-29 07:52 · 字数 834 · 阅读 14 ...

  • API网关Kong(一):Nginx、OpenResty和Kon

    作者:李佶澳 转载请保留:原文地址 发布时间:2018-09-29 15:41:50 +0800 说明 Nginx...

  • Ubuntu16.04 PHP7.0升级7.2

    2018-09-29 实践Laravel项目过程中需要使用 Composer 安装最低支持版本 php7.1 的 ...

  • 04_HTML 内联框架和超链接标签

    时间:2018-09-29 姓名:魏文应 一、内联框架 在当前 html 引入另外一个 html 文件: src=...

  • Java基础-数组

    2018-09-29 格式:1)、动态初始化数据类型 [] 数组名称 = new 数据类型[100]; 2) 静态...

网友评论

      本文标题:2018-09-29

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