Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 为什么此代码不动态设置文档标题?_Jquery - Fatal编程技术网

Jquery 为什么此代码不动态设置文档标题?

Jquery 为什么此代码不动态设置文档标题?,jquery,Jquery,我试图定期从php脚本中动态更新文档标题,但似乎不起作用。我是jquery的初学者,请帮助 <div id="code" style="border: 1px solid; "></div> <script> var blink = true; setInterval(function(){ if(blink){ jQuery('#code').load('test.php', function(result)

我试图定期从php脚本中动态更新文档标题,但似乎不起作用。我是jquery的初学者,请帮助

 <div id="code" style="border: 1px solid; "></div>
    <script>
     var blink = true;

    setInterval(function(){

    if(blink){
    jQuery('#code').load('test.php', function(result) {
    var theTitle = document.getElementsByTagName("title")[0];   
         theTitle= 'google'+jQuery('#code').html();

    });

        //theTitle.text =document.getElementById('code').value;
        blink = false;
    }else{

     jQuery('#code').load('test.php', function(result) {
    var theTitle = document.getElementsByTagName("title")[0];   
         theTitle= 'yahoo'+jQuery('#code').html();

    });

        blink = true;
    }
    }, 2000);

var闪烁=真;
setInterval(函数(){
如果(闪烁){
jQuery('#code').load('test.php',函数(结果){
var theTitle=document.getElementsByTagName(“标题”)[0];
标题='google'+jQuery('#code').html();
});
//title.text=document.getElementById('code').value;
闪烁=假;
}否则{
jQuery('#code').load('test.php',函数(结果){
var theTitle=document.getElementsByTagName(“标题”)[0];
标题='yahoo'+jQuery('#code').html();
});
闪烁=真;
}
}, 2000);
试试看-

document.title = "new page title."
试一试-


如果使用jquery,请尝试以下操作:

var blink = true;
setInterval(function(){
    $('#code').load('test.php', function(result) {
         $('title').text(blink ? 'google'+$('#code').html() : 'yahoo'+$('#code').html());
         blink = !blink;
    });
}, 2000);

如果使用jquery,请尝试以下操作:

var blink = true;
setInterval(function(){
    $('#code').load('test.php', function(result) {
         $('title').text(blink ? 'google'+$('#code').html() : 'yahoo'+$('#code').html());
         blink = !blink;
    });
}, 2000);