js function to get filename from url

前端 未结 19 2619
挽巷
挽巷 2020-11-30 03:01

I have a url like http://www.example.com/blah/th.html

I need a javascript function to give me the \'th\' value from that.

All my urls have the same format (2

19条回答
  •  佛祖请我去吃肉
    2020-11-30 03:28

    Using jQuery with the URL plugin:

    var file = jQuery.url.attr("file");
    var fileNoExt = file.replace(/\.(html|htm)$/, "");
    // file == "th.html", fileNoExt = "th"
    

提交回复
热议问题