jQuery 버튼 텍스트 변경

211.104.171.24 (토론)님의 2022년 3월 2일 (수) 14:39 판 (→‎방법: button 태그는 html())
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

jQuery 버튼 텍스트 변경
jQuery 버튼 텍스트 바꾸기

1 방법: button 태그는 html()

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function() {
  $('#button1').click( function() {
    if( $(this).html() == '인증번호 받기' ) {
      $(this).html('확인');
    }
    else {
      $(this).html('인증번호 받기');
    }
  });
});
</script>
 
<button id='button1'>인증번호 받기</button>

2 방법: input 태그는 val()

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function() {
  $('#button1').click( function() {
    if( $(this).val() == '접기' ) {
      $(this).val('펼치기');
    }
    else {
      $(this).val('접기');
    }
  });
});
</script>
 
<input type='button' value='접기' id='button1' />

3 같이 보기

4 참고

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