使用 Javascript 更改标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6715339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 22:54:10  来源:igfitidea点击:

Change Title With Javascript

javascriptjqueryhtmlpage-title

提问by ukung

How can I modify the existing title to the document with Jquery as mouseover title change like that on facebook title link.

当鼠标悬停在 facebook 标题链接上的标题更改时,如何使用 Jquery 修改文档的现有标题。

回答by Jordan

You don't need jQuery.

你不需要jQuery。

document.title = 'My new title here';

回答by Paul

With javascript. jQuery won't help you here:

使用 javascript。jQuery 不会在这里帮助你:

document.title = 'New Title';

You can insert that into a jQuery mouseover callback function if you want.

如果需要,您可以将其插入到 jQuery 鼠标悬停回调函数中。

回答by Toby

I'll extend on these other answers, this code should do it in entirety, just be sure to change the class in the selector, and the new Title Text.

我将扩展这些其他答案,这段代码应该完整地完成,只需确保更改选择器中的类和新的标题文本。

(function(){
    var oldtitle;
    jQuery('a.yourlink').hover(
        function () {
           oldtitle = document.title;
           document.title = 'Your New Title';
        },
        function () {
            document.title = oldtitle;
        }
    );
})();

Here is a jsfiddle demo I made that changes the text of the object, rather than the window title: http://jsfiddle.net/MpZGf/1/

这是我制作的 jsfiddle 演示,它更改了对象的文本,而不是窗口标题:http: //jsfiddle.net/MpZGf/1/

回答by The Mask

Try:

尝试:

document.title = 'title';