How to include an HTML file with jQuery?

后端 未结 3 1384
南笙
南笙 2020-12-14 03:03

I want to make my code separate so I decided to divide each div to html files. Each HTML file has some jQuery click events. I have 2 files index.html

3条回答
  •  再見小時候
    2020-12-14 03:36

    I have another solution. It seems to make code more beautiful and shorter. First define include function.

    var include = function(beReplacedId,url){
    jQuery.get(url,function(data){
        jQuery(beReplacedId).replaceWith(data);
    
    });
    

    }

    On html page use onload to trigger include like this.

    
    

    After the compiler runs through it will replace img tag and load what you need. With above trick i can attach to any place in my index.html

提交回复
热议问题