본문 바로가기
Frontend/jQuery

[jquery] jquery 이용해 alert창 띄우기

by 새벽물망초 2022. 3. 24.

https://releases.jquery.com/

 

jQuery CDN

The integrity and crossorigin attributes are used for Subresource Integrity (SRI) checking. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libr

releases.jquery.com

 

1] alert창 띄우기

	$(document).ready(function() { 
		$("#id_btn").click(function() { 
			if ($("#id_subject").val() == '') {
				alert('제목을 입력해야 해욥');
			} else if ($("#id_name").val() == '') {
				alert('이름을 입력해야 해욥');
			} else {
				$("#id_writeform").submit(); 
			}
		});
	});

jquery는 modern javascript와 다른 점이 있다면

1] function명을 $(객체(?)).행동(?)(function() { }); 이렇게 쓴다는 점

2] 객체 명을 쓸때 $("#id명") 로 쓰는데, 때문에 반드시 jsp파일의 사용할 태그 내에 id값이 있어야 한다

 

$(document).ready(function() { }); 

현재 페이지가 시작될 때 처리할 내용을 작성한다

$("#id_btn").click(function() { });

id_btn을 click하면 function을 실행한다

if ($("#id_subject").val() == '') { // 1. id_subject 의 값이 없으면
alert('제목을 입력해야 해욥'); // 2. 다음 메시지 출력하고
} else if ($("#id_name").val() == '') { // 3. id_subject 의 값은 있고 id_name 의 값이 없으면
alert('이름을 입력해야 해욥'); // 4. 다음 메시지 출력하고
} else { 5. id_subject 와 id_name 의 값 둘다 있다면
$("#id_writeform").submit(); } // 6. form 전송한다

 

 

2] form의 method와 action을 js에 지정하기

$("#id_writeform").attr("method","post");
$("#id_writeform").attr("action","/board/insert");

attr = attribute의 약자 / attr("속성명","값")

 

 

참고]

 

'Frontend > jQuery' 카테고리의 다른 글

제이쿼리 비동기 방식  (0) 2022.10.31
효과 및 애니메이션  (0) 2022.10.31
이벤트  (0) 2022.10.31
제이쿼리 기본 다지기  (0) 2022.10.30
jquery 콜백 함수  (0) 2022.03.29

댓글