"JQuery 버튼 텍스트 변경"의 두 판 사이의 차이

6번째 줄: 6번째 줄:
<script>
<script>
$(function() {
$(function() {
$('#button1').click( function() {
  $('#button1').click( function() {
if( $(this).html() == '접기' ) {
    if( $(this).html() == '접기' ) {
$(this).html('펼치기');
      $(this).html('펼치기');
}
    }
else {
    else {
$(this).html('접기');
      $(this).html('접기');
}
    }
});
  });
});
});
</script>
</script>
 
<button id='button1'>접기</button>
<button id='button1'>접기</button>
</source>
</source>

2015년 6월 24일 (수) 10:01 판

jQuery 버튼 텍스트 변경

1 예시

<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 참고 자료

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