時間帯によってメッセージを変えようとしています。
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>
Jクエリ:
<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>
私は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>