chr*_*ina 28 html javascript jquery
如果你在,http://www.cnn.com/2012/11/09/opinion/brown-pakistan-malala/index.html
你可以让Jquery抓住index.html
吗?
或者如果你在http://www.washingtonpost.com/politics/decision2012/supreme-court-to-review-key-section-of-voting-rights-act/2012/11/09/dd249cd0-216d-11e2-8448-81b1ce7d6978_story.html
回来dd249cd0-216d-11e2-8448-81b1ce7d6978_story.html
?
对于非扩展定义的页面,例如当前的页面,http://stackoverflow.com/questions/13317276/jquery-to-get-the-name-of-the-current-html-file
它可以返回"目录"结构中的最后一个"文件",例如:jquery-to-get-the-name-of-the-current-html-file
Vya*_*huk 43
虽然不是JQuery,但您可以使用以下方法访问它:
document.location.href.match(/[^\/]+$/)[0]
要么
document.location.pathname.match(/[^\/]+$/)[0]
在不需要的锚点/哈希标签(#)的情况下.
Vin*_*Vin 12
不需要jQuery.这将为您提供URL路径的最后一段(最后一个斜杠后面的位):
var href = document.location.href;
var lastPathSegment = href.substr(href.lastIndexOf('/') + 1);
Run Code Online (Sandbox Code Playgroud)
function getCurentFileName(){
var pagePathName= window.location.pathname;
return pagePathName.substring(pagePathName.lastIndexOf("/") + 1);
}
Run Code Online (Sandbox Code Playgroud)