jQuery的.load(或$。阿贾克斯)来获取和设置页面的标题? [英] jQuery .load (or $.ajax) to get and set page title?

查看:143
本文介绍了jQuery的.load(或$。阿贾克斯)来获取和设置页面的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止...

$('#container').load(hash + ' #page','', function() { 
    $('#container').fadeIn('fast');
    document.title = $('#title').load(hash + ' #title').text();
    });

...不起作用。 有没有做这更好的/正确的方法是什么?

...doesn't work. Is there a better/correct way to do this?

供参考: -

  • 我已经添加了ID #title标签(所有页/这是一个PHP模板)。
  • 在该容器.fade(ED)出预先(不太重要)

在此先感谢。

推荐答案

问题在于,当时分配给 document.title时 $('#标题')。载荷(散+'#title')。text()的可能还没有完呢。尝试将新的 document.title时在回调 .load

The problem is that, at the time you assign to document.title, the $('#title').load(hash + ' #title').text() might not have finished yet. Try setting the new document.title in the callback of that .load.

更新

尝试:

$('#container').load(hash + ' #page','', function() { 
    $('#container').fadeIn('fast');
    $('#title').load(hash + ' #title', '', function(data) {
        document.title = $(this).text();
        });
    });

这篇关于jQuery的.load(或$。阿贾克斯)来获取和设置页面的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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