웹페이지

JAVASCRIPT STEP 21 - Message

IT의 큰손 2023. 4. 24. 12:46
728x90

★ 메시지 박스, 대화상자

  • 1. void alert(message);
document.form1.btn1.onclick = m1;

function m1() {
    // alert();
    // alert(100);
    alert('문자열');
}
  • 실행 결과

실행 결과

 

  • 2. boolean confirm(message);
document.form1.btn2.onclick = m2;

function m2() {
    if(confirm('정말 삭제하겠습니까?')){
        document.body.bgColor = 'blue';
    }else {
        document.body.bgColor = 'white';
    }
}
  • 실행 결과

실행 결과

 

  • 3. string prompt(message, value);
document.form1.btn3.onclick = m3;

function m3() {
    prompt('메시지', '초기값');
}

/*
function m3() {
    var input = prompt('이름을 입력하시오.', '초기값');
    console.log(input);
}
*/
  • 실행 결과

실행 결과

 

728x90