Javascript 如何根据文件名自动更改HTML标题?

Javascript 如何根据文件名自动更改HTML标题?,javascript,jquery,html,Javascript,Jquery,Html,例如,文件名为Hello.html,如何使html标题自动变为“Hello”?javascript/jquery是否可以这样做?通过以下方式更新标题: document.title = (location.pathname.substring(location.pathname.lastIndexOf("/") + 1)).replace('.html',''); 你想让这个自动化有什么原因吗?您可以在html的头部设置一个标记。如果要使用javascript执行此操作,可以解析窗口路径,并以

例如,文件名为Hello.html,如何使html标题自动变为“Hello”?javascript/jquery是否可以这样做?

通过以下方式更新标题:

document.title = (location.pathname.substring(location.pathname.lastIndexOf("/") + 1)).replace('.html','');

你想让这个自动化有什么原因吗?您可以在html的头部设置一个标记。如果要使用javascript执行此操作,可以解析窗口路径,并以这种方式设置document.title。
document.title=document.href.split('/').pop()是,因为我正在制作1章=1个html文件。还有很多章节我要处理。编辑:如何排除“.html”?
.replace(“.html”,”)
,但我不明白为什么不能像@David建议的那样,在每个页面中添加不同的
标记……有200多个章节,生成200多个html文件。我希望每个标题都包含它们当前所在的章节号。手动编辑会非常耗时。。