jquery获取当前html文件的名称 [英] Jquery to get the name of the current html file
问题描述
如果您位于 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-the-name-of-the-current-html-file $ c
$ div class =h2_lin>解决方案
虽然不是JQuery,但您可以使用以下方式访问它:
document.location.href.match(/ [^ \ /] + $ /)[0]
或
document.location.pathname.match(/ [^ \ /] + $ /)[0]
在不需要的锚/散列标签(#)的情况下。
If you are on http://www.cnn.com/2012/11/09/opinion/brown-pakistan-malala/index.html
can you get Jquery to grab the index.html
?
or if you are on 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
have it return dd249cd0-216d-11e2-8448-81b1ce7d6978_story.html
?
And for non extension defined pages such as this current one http://stackoverflow.com/questions/13317276/jquery-to-get-the-name-of-the-current-html-file
can it return the last "file" in the "directory"structure, for example: jquery-to-get-the-name-of-the-current-html-file
Although not JQuery, you can access it using the following:
document.location.href.match(/[^\/]+$/)[0]
or
document.location.pathname.match(/[^\/]+$/)[0]
in case of unneeded anchors/hash tags (#).
这篇关于jquery获取当前html文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!