javascript - Instantiation constructor changes content without refresh? ?
黄舟
黄舟 2017-05-19 10:21:12
0
1
462
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? ? ?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
伊谢尔伦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template