gpt4 book ai didi

javascript - 从 url 获取内容并将其放置在页面上的容器中

转载 作者:行者123 更新时间:2023-11-28 02:55:39 27 4
gpt4 key购买 nike

我想使用 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

示例:http://jsbin.com/ubiwo3

关于javascript - 从 url 获取内容并将其放置在页面上的容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2734782/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com