"JQuery 폼 내부 어느 버튼인지 확인"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-== 참고 자료 == +==참고==))
잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight ))
5번째 줄: 5번째 줄:


==예시==
==예시==
<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>

2020년 11월 2일 (월) 00:41 판

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 }}