zoukankan      html  css  js  c++  java
  • A2D JS框架

    写了个微型JS框架

    主要实现了:showDialog、noConflict、定位元素、event绑定功能

    使用端的代码:

    <head>
        <title></title>
        <script src="A2D.js" type="text/javascript"></script>
        <link href="A2D.css" rel="stylesheet" type="text/css" />
        <script language="A2D" type="text/A2DTemplate" id="showDialog">     //搞了个html模版
            <div class="tooltip">{msg}</div>
        </script>
    </head>
    <body>
        <button id="a111">Test2</button>
    
        <script language="javascript" type="text/javascript">
            var newName=$.noConflict();
    newName.say(); newName.bind(newName("a111"), "click", function () {
    newName.showDialog('raised by test2 button.' + new Date()); }); </script> </body>

    A2D.js代码

    (function (wd, doc) {
        function noConflict() {
            wd.$ = _$;
            wd.A2D = A2D;
    return A2D; }
    function saySomeWord() { showDialog("My name is Aaron"); } function showDialog(msg) { var template = findA2DTemplate("showDialog"); template = A2D.helper.replace(template, "{msg}", msg); var div = document.createElement("div"); div.innerHTML = template; var first = doc.body.firstChild; doc.body.insertBefore(div, first); } function findA2DTemplate(templateId) { return A2D(templateId).innerHTML; } function bind(element, evtName, evtHandler) { if (doc.addEventListener) element.addEventListener(evtName, evtHandler, false); else element.attachEvent("on" + evtName, evtHandler); } var A2D = function (id) { return doc.getElementById(id); } A2D.noConflict = noConflict; A2D.say = saySomeWord; A2D.showDialog = showDialog; A2D.bind = bind; A2D.helper = {}; A2D.helper.replace = function (src, search, tobe) { while (src.indexOf(search) >= 0) { src = src.replace(search, tobe); } return src; } var _$ = wd.$; wd.$ = A2D; } )(window, document);

    A2D.css代码

    .tooltip
    {
        padding: 10px;
        font-size: large;
        font-style: normal;
        color: #008000;
        background-color: #CCCCFF;
        border-bottom-style: dotted;
        border-right-style: dotted;
        border-right-width: 1px;
        border-bottom-width: 1px;
        border-right-color: #C0C0C0;
        border-bottom-color: #C0C0C0;
    }

    效果图:

    给我的感觉是前端东西比较新颖,要很努力才能真正精通。

  • 相关阅读:
    0.0
    《用户故事与敏捷方法》 笔记
    Linux下运行Jmeter压测
    64位Win7系统安装Mysql 5.7.22图文教程
    Zabbix-(七)分布式监控
    Zabbix-(六) JMX监控
    Zabbix-(五)监控Docker容器与自定义jvm监控项
    Zabbix-(四)邮件、钉钉告警通知
    Zabbix-(三)监控主机CPU、磁盘、内存并创建监控图形
    Zabbix-(二) 使用docker部署
  • 原文地址:https://www.cnblogs.com/aarond/p/3232842.html
Copyright © 2011-2022 走看看