• 看看Jquery,再看看传统的JS,我们来效仿一$(function(){$(“#a”).click=function(){};});吧


    Jquery简化了传统JS实现功能的代码量,例如:

    jquery的$(function(){});相当于传统JS的window.onload=function(){};

    还是看一下我写的代码吧:

    <script type="text/javascript">
            window.onload = function() {
                //定义一个类对象
                var Zhang = {
                    Title: "",
                    Width: "100",
                    Height: "",
                    Zhang: function(title, width, height) {
                        this.Title = title;
                        this.Width = width;
                        this.Height = height;
                    },
                    Zhang: function(title, height) {//方法的重载
                        this.Title = title;
                        this.Height = height;
                    },
                    init: { target: "_blank", src: "" },
                    generate: function() {
                        var insertedNode = document.createElement('img'); //添加HTML標記
                        insertedNode.setAttribute('src', Zhang.init.src);
                        insertedNode.setAttribute("width", Zhang.Width);
                        insertedNode.setAttribute("height", Zhang.Height);

    // var newTextNode = document.createTextNode("<img src='" + Zhang.init.src

    // + "' width=" + Zhang.Width + " height=" + Zhang.Height + ">"); //添加文本

                        document.getElementsByTagName("body")[0].appendChild(insertedNode);
                    }
                }
     
                var obj = document.getElementById("add");
                Zhang.Zhang("图像测试", "300", "600"); //覆盖原来的值100
                Zhang.init.src = "http://d4.sina.com.cn/201106/03/312669_78090-biaoxian.JPG";
                if (typeof (obj.addEventListener) != "undefined") { //判断浏览器
                    obj.addEventListener("click", Zhang.generate, true); //触发单击事件
                } else {
                    obj.attachEvent("onclick", Zhang.generate); //绑定方法
                }
     
            };
        </script>
  • 相关阅读:
    最大流问题
    字符串的回文与镜像
    字符串的回文与镜像
    Aho
    linux环境变量
    【Centos7】安装memcached
    linux命令后台执行
    ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决
    ubuntu server解决不能访问外网问题
    【Ubuntu 16】安装net-snmp
  • 原文地址:https://www.cnblogs.com/lori/p/2071217.html
Copyright © 2020-2023  润新知