JavaScript not working on external file

前端 未结 4 1890
孤城傲影
孤城傲影 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条回答
  •  醉话见心
    2021-01-13 01:47

    Try adding the script tag to the bottom of your html page instead of in the header. That is done for performance reasons that way your page appears as fast as possible and the extra javascript stuff is loaded afterwards.

    You can read more about this at : How does the location of a script tag in a page affect a JavaScript function that is defined in it?

提交回复
热议问题