美文网首页
prototype练习

prototype练习

作者: 战神飘雪 | 来源:发表于2018-04-11 16:40 被阅读8次
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="jq.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <script type="text/javascript">
            var tors = function(a1,a2){
                this.name = '娃娃'
                this.age = '1岁'
                this.init(a1,a2);
            };
            tors.prototype = {
                init: function(a1,a2){
                    console.log('我init')
                    this.render();
                    this.fangfa(a1,a2);
                },
                render: function(){
                    $("body").append('<div id="buttonLink">按钮</div></br><div id="buttonLink1">按||钮</div>')
                },
                fangfa: function(a1,a2){
                    $("#buttonLink").on('click',function(){
//                      console.log('我被点击了');
//                      console.log(name);
                        console.log(a1);
                    })
                    $("#buttonLink1").on('click',function(){
//                      console.log('我被点击了');
//                      console.log(name);
//                      this.name = '泡泡糖'
                        console.log(a2);
                        console.log(name);
                        bbq.name = '狗狗'
                    })
                }
            }
            var bbq = new tors('我a1','她a2');
//          console.log(bbq)
            console.log(bbq.name);
            console.log(tors.name);
        </script>
    </body>
</html>

相关文章

网友评论

      本文标题:prototype练习

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