study/javascript
jquery click 이벤트 클릭 이벤트
땅콩잉
2021. 11. 12. 17:29
728x90
아이디가 change 인 요소를 클릭 했을 때 이벤트 캐치!
해당 소스는 특정 버튼을 눌렀을 때 서버에 데이터를 전송 후 결과값을 받기위해 사용한 것이다.
$('#change').on('click',function(){
console.log(arr);
$.ajax({
url:'/~~~~~.php',
data: {
arr: arr
},
dataType: 'json',
method: 'post'
}).done(function (result) {
location.reload();
alert(result.msg);
}).fail(function(e){
console.log(e);
alert(result.msg);
});
});
클래스가 change인 요소를 클릭했을 때!
$('.change').on('click',function(){
})
좀 오래된 jquery 버전이면 아래와 같이 쓸 수 있다.
lilve, bind 등 함수도 있다..
$( document ).delegate('.test .test1', 'click', function(){
});