<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p><a id="naver" href="https://www.naver.com">NAVER</a></p>
<script type="text/javascript">
/*
function getRandom() {
return Math.random();
} //여기까지 난수 생성
getRandom();
console.log(getRandom());
*/
function getRandomInt(min, max) {
/*
minMax = Math.round(8.80); // 반올림
min = Math.ceil(5.95); //주어진 숫자보다 크거나 같은 숫자 중 가장 작은 숫자를 반환함 << 올림
max = Math.floor(8.95); //함수는 주어진 숫자와 같거나 작은 정수 중에서 가장 큰 수를 반환합니다. << 내림
*/
mathRandom = Math.random();
return Math.round(mathRandom*2); //최댓값은 제외, 최솟값은 포함
}
getRandomInt();
console.log(getRandomInt());
var jsStr = 'string object';
var jsStrReplace = jsStr.replace('string','document');
document.write('<p>'+jsStrReplace+'</p>');
var href = document.getElementById( 'naver' ).getAttribute( 'href' );
document.write( '<p>' + href + '</p>' );
/*
<input id=Btn type="button" value=""> << html이였음
var btnValue = document.querySelector('#Btn').getAttribute('value'); // id Btn 의 속성값인 value를 선택함
btnValue = document.write('button')
>>안되는 이유 : getAttribute가 string이여서 value를 바꿀수가 없당,,,,
*/
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input id="popup_btn" type="button" value="notice" onclick="popUpBtn()">
<script type="text/javascript">
function popUpBtn(){
var popBtn = document.querySelector('#popup_btn');
var alramText = ' Hello my name is HEINI \n Hello my name is HEINI \n Hello my name is HEINI \n Hello my name is HEINI \n Hello my name is HEINI';
var alramReplace = alramText.replaceAll('HEINI','JIM'); //문자열 전체에서 단어를 변경하고 싶다면 replaceAll을 사용하기!
console.log(alramReplace);
alert(alramReplace);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
var imgArray=new Array();
imgArray[0]="visual.png";
imgArray[1]="visual2.png";
imgArray[2]="visual3.png";
function showImage(){
var imgNum = Math.round(Math.random()*2);
var Img = document.getElementById("introimg");
Img.src = imgArray[imgNum];
setTimeout(showImage,3000);
}
</script>
</head>
<body onload="showImage()">
<div id="root">
<img id="introimg">
</div>
</body>
</html>