Get script path

前端 未结 13 1729
青春惊慌失措
青春惊慌失措 2020-11-30 01:21

In CSS, any image path is relative to the CSS file location.

f.ex if I put the CSS file in /media/css/mystyles.css and use something like



        
13条回答
  •  难免孤独
    2020-11-30 01:50

    Inspired by bobince answer above, I wrote a jQuery version. Here is the code in one line:

    var scriptpath = $("script[src]").last().attr("src").split('?')[0].split('/').slice(0, -1).join('/')+'/';
    

    Edit: Filter the script tag by the src attribute, so that we get a src to work on.

提交回复
热议问题