<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script>
    var page = page || {};
    page.dom = page.dom || {};
    page.dom.Text = function(){
        this.insert = function(where){
            var txt = document.createTextNode(this.url);
            where.appendChild(txt);
        };
    }
    page.dom.Link = function(){
        this.insert = function(where){
            var link = document.createElement('a');
            link.href = this.url;
            link.appendChild(document.createTextNode(this.href));
            where.appendChild(link);
        };
    }
    page.dom.Image = function(){
        this.insert = function(where){
            var im = document.createElement('img');
            im.src = this.url;
            where.appendChild(im);
        }
    }
    page.dom.factory = function(type){
        return new page.dom[type]
    }
</script>
</body>
</html>

工厂模式,抄自tamu大叔博客的

相关文章:

  • 2021-10-23
  • 2021-07-13
  • 2022-12-23
  • 2021-08-22
  • 2021-06-10
  • 2021-09-04
  • 2022-01-26
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-02-13
  • 2021-12-24
  • 2021-12-26
相关资源
相似解决方案