jQuery: how to change title of document during .ready()?

前端 未结 8 1828
逝去的感伤
逝去的感伤 2020-11-27 12:37

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 co

相关标签:
8条回答
  • 2020-11-27 13:24
    <script type="text/javascript">
    $(document).ready(function() {
    
        $(this).attr("title", "sometitle");
    
    });
    </script>
    
    0 讨论(0)
  • 2020-11-27 13:26

    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.

    The correct way to do this is on the server side.

    In your layout, there at some point will be some code which puts the text in the div. Make this code also set some instance variable such as @page_title, and then in your outer layout have it do <%= @page_title || 'Default Title' %>

    0 讨论(0)
提交回复
热议问题