jQuery:如何在.ready()期间更改文档的标题? [英] jQuery: how to change title of document during .ready()?

查看:111
本文介绍了jQuery:如何在.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>

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

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