我想使用 jQuery 从 url 中查找最后一个页面名称/目录并将其显示在 <h3>
中的页面上容器。例如:/_blog/PunkLogic_News/tag/videos/我想在特定的 <h3 class="urltag">
中显示“视频”在页面上。/_blog/PunkLogic_News/tag/Noosa_Biosphere/我想显示“Noosa Biosphere”而不带下划线。我想所有特殊字符也需要删除。
预先感谢您的帮助。
jackson
最佳答案
这应该可以做到:
var title = location.href.match(/([^\/]*)\/?$/)[1]; //get the last token
title = title.replace(/[^a-z\d\s]+/ig, ' '); //remove non-alphanumeric characters
$('h3.urltag').text(title); //set the title to h3
关于javascript - 从 url 获取内容并将其放置在页面上的容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2734782/