zoukankan      html  css  js  c++  java
  • 看看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>
  • 相关阅读:
    羊年春节微信数据大解析
    微信公众号推荐(自己关注的微信公众平台导航)
    微信要革"传统电视"的命吗?
    微信是在学苹果模式吗?
    发微信红包啦!借花献佛
    有原创保护能力的公众帐号可申请页面模版功能和图文消息正文插入历史群发链接
    编程能力与编程年龄
    代码执行的效率
    对九个超级程序员的采访
    编程真难啊
  • 原文地址:https://www.cnblogs.com/lori/p/2071217.html
Copyright © 2011-2022 走看看