我試圖根據一天中的時間更改消息。根據一天中的時間更改消息?
我貼我在尋找什麼在ST2爲JSFiddle
這就是:
<div class="container">
<div id="time">
<p id="time">Good morning.</p>
</div>
<div>
<p>I used to work in the marketing industry.<br>Now I'm a Web Designer and Developer.<br> I like to keep things simple.</p>
</div>
的Jquery:
<script type="text/javascript">
$(document).ready(function()
{
var now = new Date();
var hours = now.getHours();
var msg;
if(hours<12)
msg = "Good Morning";
else if(hours<18)
msg = "Good Afternoon";
else
msg = "Good Evening";
return(msg);
});
});
</script>
我一個完整的noob當它涉及到jquery所以要溫柔。
HTML:
<!DOCTYPE html>
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var now = new Date();
var hours = now.getHours();
var msg;
if (hours < 12) msg = "Good Morning";
else if (hours < 18) msg = "Good Afternoon";
else msg = "Good Evening";
$('#time p').text(msg);
});
});
</script>
</head>
<body>
<div class="container">
<div id="time">
<p>Good morning.</p>
</div>
<div>
<p>I used to work in the marketing industry.<br>Now I'm a Web Designer and Developer.<br> I like to keep things simple.</p>
</div>
</div>
</body>
你需要告訴它把味精放在哪裏。定位p標籤,通過提供id,名稱等,然後將該標籤的文本設置爲msg。 –