~/ equivalent in javascript

后端 未结 12 1965
萌比男神i
萌比男神i 2020-12-12 19:11

Any smart way of doing a \"root\" based path referencing in JavaScript, just the way we have ~/ in ASP.NET?

12条回答
  •  一向
    一向 (楼主)
    2020-12-12 20:07

    I usually create a variable at the top of the js file and assign it the root path. Then I use that variable when referencing a file.

    var rootPath = "/";
    image.src = rootPath + "images/something.png";
    

提交回复
热议问题