JavaScript not working on external file

前端 未结 4 1848
孤城傲影
孤城傲影 2021-01-13 01:01

When I use this code inside my HTML document it\'s working:

$(\'a.tocenter[href*=#]\').click( function() {
    if (location.pathname.replace(/^\\//,\'\') ==          


        
4条回答
  •  -上瘾入骨i
    2021-01-13 01:48

    Wrap the content inside your file in

    $(function(){
    //js goes here
    });
    

    or put the reference to the file at the bottom of your page

    this allows the DOM to load before executing your script.

提交回复
热议问题