用jQuery更改标签标题?

时间:2018-12-04 11:11:42

标签: javascript jquery html tabs

我正在这个网站上为一个朋友工作,所以在页面刷新时,随机选择一个字母星座(并且标签标题更改为对应),然后在晚上9点至午夜之间选择一个星座(称为“金岩石”)加入页面上的任意一个..

例如,我们希望标签标题能够读取+“和Gold Rocks”时页面上的所有内容。

制表符之前的位置。 润唇膏 鸡皮Work工作

应该在晚上9点至午夜之间 润唇膏和金石 鸡皮and和金岩石

我的代码哪里出问题了?

是否可以仅使用Javascript?

<title></title>

+

<script>

//CHOOSES CONSTELLATION + CHANGES TAB !

var chooses = Math.floor(Math.random() * 2) + 1;
var title = $(document).prop('title');

//LIPBALM !

    if (chooses == 1) {
document.write('<div class="lipbalm"><div class="lipbalm-l"><a href="http://sarahboulton.co.uk">L</a></div><div class="lipbalm-i"><a href="http://sarahboulton.co.uk">i</a></div><div class="lipbalm-p"><a href="http://sarahboulton.co.uk">p</a></div><div class="lipbalm-b"><a href="http://sarahboulton.co.uk">B</a></div><div class="lipbalm-a"><a href="http://sarahboulton.co.uk">a</a></div><div class="lipbalm-l2"><a href="http://sarahboulton.co.uk">l</a></div><div class="lipbalm-m"><a href="http://sarahboulton.co.uk">m</a></div></div>');

$(document).prop('title', 'Lip Balm');
}


//GOOSEBUMPS WORK !

    if (chooses == 2) {
document.write('<div class="goosebumpswork"><div class="goosebumpswork-g"><a href="http://sarahboulton.co.uk">G</a></div><div class="goosebumpswork-o"><a href="http://sarahboulton.co.uk">o</a></div><div class="goosebumpswork-o2"><a href="http://sarahboulton.co.uk">o</a></div><div class="goosebumpswork-s"><a href="http://sarahboulton.co.uk">s</a></div><div class="goosebumpswork-e"><a href="http://sarahboulton.co.uk">e</a></div><div class="goosebumpswork-b"><a href="http://sarahboulton.co.uk">b</a></div><div class="goosebumpswork-u"><a href="http://sarahboulton.co.uk">u</a></div><div class="goosebumpswork-m"><a href="http://sarahboulton.co.uk">m</a></div><div class="goosebumpswork-p"><a href="http://sarahboulton.co.uk">p</a></div><div class="goosebumpswork-s2"><a href="http://sarahboulton.co.uk">s</a></div><div class="goosebumpswork-w"><a href="http://sarahboulton.co.uk">W</a></div><div class="goosebumpswork-o3"><a href="http://sarahboulton.co.uk">o</a></div><div class="goosebumpswork-r"><a href="http://sarahboulton.co.uk">r</a></div><div class="goosebumpswork-k"><a href="http://sarahboulton.co.uk">k</a></div></div>');

$(document).prop('title', 'Goosebumps Work');
}


</script>

+

<script type="text/javascript">

//GOLD ROCKS ! only between 9pm and midnight

var currentTime = new Date().getHours();

//if it is between 9pm and midnight
if (21 <= currentTime && currentTime < 24) 
{
document.write('<div class="goldrocks"><div class="goldrocks-g"><a href="http://sarahboulton.co.uk">G</a></div><div class="goldrocks-o"><a href="http://sarahboulton.co.uk">o</a></div><div class="goldrocks-l"><a href="http://sarahboulton.co.uk">l</a></div><div class="goldrocks-d"><a href="http://sarahboulton.co.uk">d</a></div><div class="goldrocks-r"><a href="http://sarahboulton.co.uk">R</a></div><div class="goldrocks-o2"><a href="http://sarahboulton.co.uk">o</a></div><div class="goldrocks-c"><a href="http://sarahboulton.co.uk">c</a></div><div class="goldrocks-k"><a href="http://sarahboulton.co.uk">k</a></div><div class="goldrocks-s"><a href="http://sarahboulton.co.uk">s</a></div></div>');


$(document).prop('title', title+' and Gold Rocks');
}


</script>

http://sarahboulton.co.uk/kitchen.html

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以简单地使用它:

$("head title")[0];