zoukankan      html  css  js  c++  java
  • JavaScript,这是实例方法吗?

    我就看看,我不说话。

    这是 Box.js 文件:

    /// <reference path="jquery-1.8.2.min.js" />
    
    function Box(input) {
        var me = this;
        this.things = input;
        this.say = "You got a " + me.things;
    
    this.onclick = function (sender) { alert(me.say); };
    this.putOn = function (stage) { $(stage).html("Here is a box with " + me.things+"s."); stage.onclick = function () { return me.onclick(me); }; } }

    使用 Box

    <html>
    <head>
        <title>JavaScript Box</title>
        <style type="text/css">
            div { border: 1px solid gray; width: 220px; height: 50px; text-align:center; line-height:50px; cursor:pointer;}
        </style>
        <script src="Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
        <script src="Scripts/Box.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                var a = new Box("pear");
                a.putOn($("#div1").get(0));
                
                var b = new Box("book");
                b.putOn($("#div2").get(0));
    
                b.onclick = function (sender) { alert(sender.say + ", but it is not yours." ); };
            });
        </script>
    </head>
    <body>
        <div id="div1"></div>
        <br />
        <div id="div2"></div>
    </body>
    </html>

    效果:

    --

  • 相关阅读:
    Git远程库
    Git的使用
    如何利用IO流复制文件
    Lambda表达式
    Lambda表达式的标准格式
    线程池的使用步骤
    解决线程安全的三个方法
    多线程
    位运算
    如何用javadoc生成java帮助文档
  • 原文地址:https://www.cnblogs.com/i0air/p/2767877.html
Copyright © 2011-2022 走看看