28_a 태그로 함수 호출하기
HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JavaScript 함수</title> | |
<script type = "text/javascript" src="getDate.js"></script> | |
</head> | |
<body> | |
<p id="test"></p> | |
<a href="javascript:getDate()">오늘의 날짜는?</a> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//getDate() | |
function getDate() { | |
var result = ""; | |
var year = new Date().getFullYear(); | |
//getMonth 메서드는 0월부터 시작하므로 +1 | |
var month = new Date().getMonth() + 1 | |
var day = new Date().getDate(); | |
result = year + "-" + month + "-" + day; | |
document.getElementById("test").innerHTML = result; | |
} |
댓글남기기