zoukankan      html  css  js  c++  java
  • 简单的javascript--test2

    插件: jquery, sweetalert (http://t4t5.github.io/sweetalert/ )

    1.index.html

    <!DOCTYPE HTML>
    <html >
        <head>
            <meta charset="utf-8"/>
            <script type="text/javascript"  src="jquery.js"></script>    
            <script type="text/javascript"  src="sweetalert.min.js"></script>
            <link rel="stylesheet" type="text/css" href="sweetalert.css">
            <script type="text/javascript"  src="factory.js"></script>
    
        </head>
        
        <body>
            <input type="text" placeholder="haha"  value="aa"/>
        
        </body>
    
    </html>

    2. factory.js

     1 $(document).ready(function() {
     2     swal("Here's a message!");
     3     
     4     $('body').on('click', 'input', function() {
     5         var aaa = new SportFactory('worldCup').intro;
     6         $('body input:first').val(aaa);
     7         createPop('test', $('body input:first').val());
     8     });
     9 });
    10 
    11 function createPop(type, text) {
    12     var o = new Object();
    13     o.content = text;
    14     if(type === 'alert') {
    15         swal(o.content);
    16     }
    17     if(type === 'test') {
    18         swal('提示', o.content, 'success');
    19     }
    20     return o;
    21 }
    22 
    23 var SportFactory = function(name) {
    24     switch(name) {
    25         case 'NBA' :
    26             return new Basketball();
    27         case 'worldCup' :
    28             return new Football();
    29     }
    30 }
    31 
    32 var Basketball = function() {
    33     this.intro = '篮球盛行于美国';
    34 }
    35 
    36 Basketball.prototype = {
    37     getMember : function() {
    38         console.log('每个队伍需要5个队员');
    39     },
    40     
    41     getBallSize : function() {
    42         console.log('篮球很大');
    43     }
    44 }
    45 
    46 var Football = function() {
    47     this.intro = '足球在世界范围内很流行';
    48 }
    49 
    50 Basketball.prototype = {
    51     getMember : function() {
    52         console.log('每个队伍需要11个队员');
    53     },
    54     
    55     getBallSize : function() {
    56         console.log('足球很大');
    57     }
    58 }
  • 相关阅读:
    缩略图架构实现
    基于GDAL实现的PCA变换(主成分分析)
    【OpenGL】GLSL中的函数和子程序(subroutines)
    【OpenGL】关于OpenGL中Bind函数的理解
    使用MTL库求解矩阵特征值和特征向量
    C#键盘事件列表
    C#用 SendKyes 结合 Process 或 API FindWindow、SendMessage(PostMessage) 等控制外部程序
    什么是句柄
    在DLL中产生对话框的方法一(Win32 DLL)
    C# 四舍五入
  • 原文地址:https://www.cnblogs.com/maduar/p/5156204.html
Copyright © 2011-2022 走看看