Javascript 이벤트

Javascript 이벤트

< !DOCTYPE html >

< html >

< head >

< meta charset = "UTF-8" >

< title > Insert title here < / title >

< script type = "text/javascript" >

function xxx() {

console .log( "-------------------" );

alert ( "submit" );

}

function xxx2() {

var id = document . getElementById ( 'userid' ).value;

var passwd = document . getElementById ( 'passwd' ).value;

var result = false ; //호출한 곳으로 return시킬 값

//id가 3글자 이상 . pw가 입력된 경우 return = true

if (id. length > = 3 & & passwd. length ! = 0 ) {

result = true ;

} else {

result = false ; //false로 리턴이 나오면 액션이 수행이 안됨

alert ( "다시입력하세요" );

}

return result;

}

function xxx3(e) {

alert ( "xxx3 submit" );

e.preventDefault(); //action 금지, 실행은 되지만 action부분이 실행이 X

//매개변수로 넘어온 이벤트 동작정지 !

}

< / script >

< / head >

< body >

< form action = "target.html" onsubmit = "xxx()" >

아이디11111 < input type = "text" name = "userid" > < br >

비밀번호1111 < input type = "text" name = "passwd" > < br >

< button > 버튼 < / button >

< input type = "submit" value = "로그인" >

< input type = "reset" value = "취소" >

< / form >

< hr >

< form action = "target.html" onsubmit = "return xxx2()" >

아이디22222 < input type = "text" name = "userid" id = "userid" > < br >

비밀번호2222 < input type = "text" name = "passwd" id = "passwd" > < br >

< button > 버튼 < / button >

< input type = "submit" value = "로그인" >

< input type = "reset" value = "취소" >

< / form >

< hr >

< form action = "target.html" onsubmit = "xxx3(event)" >

아이디33333 < input type = "text" name = "userid" id = "userid" > < br >

비밀번호3333 < input type = "text" name = "passwd" id = "passwd" > < br >

< button > 버튼 < / button >

< input type = "submit" value = "로그인" >

< / form >

< / body >

from http://cocoshin.tistory.com/37 by ccl(A) rewrite - 2021-12-12 18:02:25