search

Home  >  Q&A  >  body text

javascript - Instantiation constructor changes content without refresh? ?

var Test = function(data){
    this.data = data
}
Test.prototype = {
    initHtml: function(){
        var html = '<p class="test">'+ this.data +'</p>'
        return html
    },
    create: function(){
        $('body').append(this.initHtml())
        this.initEvent()
    }
}

There are many similar constructors Test1, Test2...

on the page

Generate content in the page through new Test1('I am the content'), new Test2('I am the content')

Could you please tell me how to modify the constructor or other methods so that when new Test1 ('other content') is used, the content generated in the page by new Test1 ('I am the content') will be correspondingly modified

Single case mode? ? ?

黄舟黄舟2782 days ago492

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:23:12

    $('body').append(this.initHtml()) 改成 $('body').html(this.initHtml())

    reply
    0
  • Cancelreply