728x90
์กฐ๊ฑด - 'Script๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํ์ด๋ด ์๋ค.'
1.
์ฝ๋ ํผ์น๊ธฐ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body id="bodycolor" style="background-color: "" ">
<h1>๋ฐฐ๊ฒฝ์์ ๋ณ๊ฒฝ</h1>
๋ค์ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํํ์ด์ง์ ๋ฐฐ๊ฒฝ์์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
<br><br>
<button type="button" id="red" onclick="changecolor(1)">๋นจ๊ฐ</button>
<button type="button" id="green" onclick="changecolor(2)">๋
น์</button>
<button type="button" id="blue" onclick="changecolor(3)">์ฒญ์</button>
<button type="button" id="orange" onclick="changecolor(4)">์ฃผํฉ์</button>
<button type="button" id="black" onclick="changecolor(5)">๊ฒ์ ์</button>
<button type="button" id="white" onclick="changecolor(6)">ํฐ์</button>
<script type="text/javascript">
let obj = document.getElementById("bodycolor");
function changecolor(num){
if(num == 1){
obj.style.backgroundColor="red";
}
if(num == 2){
obj.style.backgroundColor="green";
}
if(num == 3){
obj.style.backgroundColor="blue";
}
if(num == 4){
obj.style.backgroundColor="orange";
}
if(num == 5){
obj.style.backgroundColor="black";
}
if(num == 6){
obj.style.backgroundColor="white";
}
}
</script>
</body>
</html>
2.
์ฝ๋ ํผ์น๊ธฐ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>ํ์ํฉ๋๋ค</h1>
<br>
โปํ์ฌ์๊ฐ์<input type="text" id="timemonitor" value="ํ์ฌ์๊ฐ">์
๋๋ค.
<script type="text/javascript">
let datetime = new Date();
alert(datetime.getHours()+":"+datetime.getMinutes()+":"+datetime.getSeconds()); //ํ์ธ์ฉ
let wholetime = datetime.getHours()+":"+datetime.getMinutes()+":"+datetime.getSeconds(); //์๋ถ์ด
document.getElementById("timemonitor").value=wholetime;
</script>
</body>
</html>
3.
์ฝ๋ ํผ์น๊ธฐ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>(๋ฌธ์ )</h1>
์์ด ์๋ด์ผ๋ก "1์ผ 1๊ฐ์ฉ ๋จน์ผ๋ฉด ์์ฌ ํ์์๋ค"๋ผ๊ณ ํ๋ ๊ณผ์ผ์ ๋ฌด์์ผ๊น์?
<br><br>
<input type="checkbox" id="answerlow">์์ด(์๋ฌธ์)๋ก ๋ตํ๋ค
<br><br>
๋ต : <input type="text" id="answerzone">
<br><br>
<button type="button" id="confirm" onclick="confmethod()">๋ต์์ฒตํฌ</button>
<script>
function confmethod() {
let low = document.getElementById('answerlow').checked;
let answer = document.getElementById('answerzone').value;
if(low == true){
if(answer == "apple" || answer == "APPLE" || answer == 'Apple'){
alert('์ ๋ต์
๋๋ค');
}else{
alert('์ค๋ต์
๋๋ค');
}
}else{
if(answer == '์ฌ๊ณผ' || answer == '๋ฅ๊ธ'){
alert('์ ๋ต์
๋๋ค');
}else{
alert('์ค๋ต์
๋๋ค');
}
}
}
</script>
</body>
</html>
4.
์ฝ๋ ํผ์น๊ธฐ ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>๋ฏธ์ ๊ด ๋ฐ ๋ฐ๋ฌผ๊ด์ ๋งํฌ</h1>
<form name="f1">
<select name="locationname" onchange="golink()">
<option>-๋์์ ์ ํ</option>
<option value="http://sema.seoul.go.kr">-์์ธ์๋ฆฝ๋ฏธ์ ๊ด</option>
<option value="http://www.mmca.go.kr">-๊ตญ๋ฆฝํ๋๋ฏธ์ ๊ด</option>
<option value="http://www.sac.or.kr">-์์ ์์ ๋น</option>
<option value="http://www.museum.go.kr">-๊ตญ๋ฆฝ์ค์๋ฐ๋ฌผ๊ด</option>
<option value="http://www.museum.seoul.kr">-์์ธ์ญ์ฌ๋ฐ๋ฌผ๊ด</option>
<option value="http://www.nfm.go.kr">-๊ตญ๋ฆฝ๋ฏผ์๋ฐ๋ฌผ๊ด</option>
</select>
</form>
<script type="text/javascript">
function golink(){
let n= document.f1.locationname.selectedIndex;
if(n!=0){
location.href=document.f1.locationname.options[n].value;
}
}
</script>
</body>
</html>
5.
์ฝ๋ ํผ์น๊ธฐ ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>2๊ฐ์ ์ฃผ์ฌ์</h1>
๋ฒํผ์ ํด๋ฆญํ๋ฉด 2๊ฐ์ ์ฃผ์ฌ์๊ฐ ๋๋ค์ผ๋ก ๋์จ๋ค.<br><br>
<table>
<tr>
<td style="padding-right: 15px;"><img alt="" src="sai_1.gif"> </td>
<td><img alt="" src="sai_6.gif"> </td>
</tr>
</table>
<br>
<button type="button" onclick="randomDice()">์ฃผ์ฌ์ ๊ตด๋ฆผ.</button>
<script type="text/javascript">
var diceNum = 1;
var diceNum2 = 6;
var count = 5;
var time = 0;
function throwDice() {
count = count - 1;
if(count != 0) {
diceNum = diceNum+1;
if(diceNum == 7) {
diceNum = 1;
}
var imgsrc = document.getElementsByTagName("img")[0];
var str = "sai_"+diceNum+".gif";
imgsrc.src = str;
diceNum2 = diceNum2 - 1;
if(diceNum2 == 0) {
diceNum2 = 6;
}
var imgsrc2 = document.getElementsByTagName("img")[1];
var str2 = "sai_"+diceNum2+".gif";
imgsrc2.src = str2;
}
else if(count==0){
clearInterval(time);
var num = Math.floor(Math.random()*6)+1;
var num2 = Math.floor(Math.random()*6)+1;
var imgsrc = document.getElementsByTagName("img")[0];
var str = "sai_"+num+".gif";
imgsrc.src = str;
var imgsrc2 = document.getElementsByTagName("img")[1];
var str2 = "sai_"+num2+".gif";
imgsrc2.src = str2;
}
}
function randomDice() {
count = 10;
clearInterval(time);
time = setInterval("throwDice()",50);
}
</script>
</body>
</html>
6.
์ฝ๋ ํผ์น๊ธฐ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>๋ค์ ์์ผ๊น์ง ๋จ์ ์ผ์</h1>
<br>
<pre>
๋ค์ ๋ฒํผ์ ํด๋ฆญํ์ฌ ์์ผ์ ์
๋ ฅํ๋ฉด,
๋ค์ ์์ผ๊น์ง ๋จ์ ์ผ์๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
</pre>
<button id="pushbutton" onclick="calbirth()">์์ผ์ ์
๋ ฅ</button>
<input type="text" id="ide">
<script>
function calbirth(){
let birthMonth = prompt("๋ช์์ธ๊ฐ์? 1 ~ 12","");
let birthDate = prompt("๋ช์ผ ์ธ๊ฐ์? 1~31","")
let now = new Date();
let birthday = new Date(birthMonth+"/"+birthDate+"/"+now.getFullYear());
birthday.setMonth(birthMonth-1);
birthday.setDate(birthDate);
let monthSec = birthday.getTime() - now.getTime();
if(monthSec <= 0){
birthday.setFullYear(now.getFullYear()+1);
monthSec = birthday.getTime() - now.getTime();
}
let days = monthSec / (24 * 60 * 60 * 1000)
days = Math.ceil(days);
alert("๋ค์ ์์ผ๊น์ง" + days + "์ผ ๋จ์");
}
</script>
</body>
</html>
๋ ์ข์ ์ฝ๋๊ฐ ์๋ค๋ฉด confirm ๋ถํ๋๋ฆฝ๋๋ค.
๊ฐ์ฌํฉ๋๋ค.
๋๊ธ