Best way to execute js only on specific page

前端 未结 4 1883
慢半拍i
慢半拍i 2020-11-28 22:13

I was wondering what would be the best way to execute a java-script code only on specific pages.

Let\'s imagine we have a template-based web-site, rewrite rule for t

4条回答
  •  广开言路
    2020-11-28 22:37

    Set a class attribute to your body tag.

    
    

    And then in your script..

    $(function(){
      if($('body').is('.PageType')){
        //add dynamic script tag  using createElement()
        OR
        //call specific functions
      }
    });
    

提交回复
热议问题