Change Title With Javascript

2019-01-27 13:00发布

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

4条回答
虎瘦雄心在
2楼-- · 2019-01-27 13:28

With javascript. jQuery won't help you here:

document.title = 'New Title';

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

查看更多
看我几分像从前
3楼-- · 2019-01-27 13:37

You don't need jQuery.

document.title = 'My new title here';
查看更多
可以哭但决不认输i
4楼-- · 2019-01-27 13:37

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/

查看更多
迷人小祖宗
5楼-- · 2019-01-27 13:37

Try:

document.title = 'title';
查看更多
登录 后发表回答