IT분야/Javascript

[JavaScript]jquery dialog enter 누를시 닫히는 현상

suroMind 2013. 12. 15. 15:19

출처 : http://codingrecipes.com/jquery-ui-dialog-and-the-enter-return-key-problem

         http://blog.naver.com/PostView.nhn?blogId=lcoguss&logNo=199048137


jquery dialog로 창을 띄워놓고

html의 input 에서 문자 입력 후에 enter를 누를 시 dialog가 닫혀버리는 현상이 있다.


아래처럼 keyCode가 13일때 아무런 처리를 하지 않으면 된다.


$('.dialog').find('input').keypress(function(e) {
	if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
		//$(this).parent().parent().parent().parent().find('.ui-dialog-buttonpane').find('button:first').click(); /* Assuming the first one is the action button */
		return false;
	}
});