嘿,我有大约10个php页面,它们的标题都是这样编码的
< title >some title here< /title>
我使用jquery的$('title').html('new title')
来动态改变标题,但这改变了所有php页面的标题。是否有一种方法来指定我想要更改其标题的页面。我使用一个。js脚本的十页,所以任何代码引用文档将影响所有的10个php页面。我只想影响比如thisone。php
谢谢。
很简单。
document.title="YOUR TITLE HERE";
把它放到你的jQuery函数中。
编辑:OP的问题更新。
如果您的标题定期更改,但仅在某些PHP文件中更改,则只包含更改这些PHP文件标题的代码。
hope this help
var url =document.URL
var title=''
switch (url)
{
case "abc.com/1.php":
title="title1";
break;
case "abc.com/2.php":
title="title2";
break;
default:
title="titledefault";
}
document.title = title;
您可以在PHP生成的html中添加一个属性,如<html title='Your title'>
你的代码看起来像这样:
document.title = $('html')attr('title');
试试这样:
$(document).ready(function ()
{
document.title = "Hello World!";
});