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

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

选项卡之前的位置
润唇膏
鸡皮Work工作

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

代码哪里出问题了?

是否可以仅使用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

谢谢 !

最佳答案

您可以简单地使用它:

$("head title")[0];

关于javascript - 用jQuery更改标签标题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53611652/

10-12 16:22