如何在 .ready() 期间更改文档的标题? [英] How can I change the title of the document during .ready()?

查看:22
本文介绍了如何在 .ready() 期间更改文档的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ruby on Rails 中使用了一些嵌套布局,在其中一种布局中,我需要从 div 中读取一个字符串并将其设置为文档的标题.设置文档标题的正确方法(如果有)是什么?

I am using some nested layouts in Ruby on Rails, and in one of the layouts i have a need to read in a string from a div and set that as the title of the document. What is correct way (if any) to set the title of the document?

<script type="text/javascript">
$(document).ready(function() {

    // ???

});
</script>

推荐答案

以下应该可以工作,但与 SEO 不兼容.最好将标题放在标题标签中.

The following should work but it wouldn't be SEO compatible. It's best to put the title in the title tag.

<script type="text/javascript">

    $(document).ready(function() {
        document.title = 'blah';
    });

</script>

这篇关于如何在 .ready() 期间更改文档的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆