Last active
October 20, 2018 05:19
-
-
Save peter279k/40a5946834f55bcb38b82275b41ee697 to your computer and use it in GitHub Desktop.
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> | |
<title>date-test</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<div id="text"></div> | |
<h2 id="result"></h2> | |
<img id="image" style="-webkit-user-select: none; cursor: zoom-in;" src="" onerror="ImageErr(this)" width="383" height="695" /> | |
<script> | |
function ImageErr(source) { | |
source.src = null; | |
source.onerror = ""; | |
source.setAttribute("style", "display: none;"); | |
document.getElementById("result").innerHTML = "image did not found"; | |
return true; | |
} | |
var dat = new Date(); | |
var year = dat.getFullYear(); | |
year = "" + year; | |
var month = dat.getMonth() + 1; | |
var day = dat.getDate(); | |
if(day <= 9) | |
day = "0" + day; | |
else | |
day = "" + day; | |
if(month <= 9) | |
month = "0" + month; | |
else | |
month = "" + month; | |
var className = "4B"; | |
var requestStr = year + month + day + className + ".jpg"; | |
var url = "http://www.wcbss.edu.hk/learn_teach/homework/" + requestStr; | |
//錯誤照片範例,會觸發 ImageErr 方法 | |
//var url = "http://www.wcbss.edu.hk/learn_teach/homework/201509084B.jpg"; | |
var text = document.getElementById("text"); | |
var image = document.getElementById("image"); | |
image.setAttribute("src", url); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment