jQuery 폼 내부 어느 버튼인지 확인

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 00:41 판 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight ))

jQuery 폼 내부 어느 버튼인지 확인
jQuery 폼에서 어느 버튼이 클릭되었는지 확인

1 예시

<syntaxhighlight lang='html5'> <script src="//code.jquery.com/jquery.min.js"></script> <script> $(function () { $('#myform').on('submit', function(event) { event.preventDefault(); var btn_class = $(document.activeElement).attr('class'); $('body').append('
'+btn_class); }); }); </script>

<form id='myform'> <button class='btn-update'>수정</button> <button class='btn-delete'>삭제</button> </form> </source>

→ 수정 버튼을 누르면 btn-update가, 삭제 버튼을 누르면 btn-delete가 출력됨
→ 예제: http://zetawiki.com/ex/jquery/which-button-in-form.php

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}