채택완료

select box에는 onclick이 안되나요??

2022-07-09 (토) 22:54:41 3,603
Copy
<div id="change-font-box" class="change-font-box">

  <input type="radio" name="ct_fontsize1" class="change-font-btn" onclick="changeFontSize('')">
      보통
  </input>
  &nbsp;
  <input type="radio" name="ct_fontsize2" class="change-font-btn" onclick="changeFontSize('-')" >
      작은글씨
  </input>
  &nbsp
  <input type="radio" name="ct_fontsize3" class="change-font-btn" onclick="changeFontSize('+')">
      큰 글씨
  </input>

</div>

 

<div id="change-font-box" class="change-font-box">
  <select class="change-font-btn" onclick="changeFontSize('')">
  <input type="radio" name="ct_fontsize1" value="">
      보통
  </input>
  &nbsp;
  <input type="radio" name="ct_fontsize2" value="-">
      작은글씨
  </input>
  &nbsp
  <input type="radio" name="ct_fontsize3" value="+">
      큰 글씨
  </input>
</select>
</div>

 

<script type="text/javascript">
            function changeFontSize(type) {
                var fontSize = $('html').css('font-size');
                fontSize = Number(fontSize.substr(0,fontSize.length-2));
                if(type === '+') {
                    fontSize += 5;
                } else if(type === '-') {
                    fontSize -= 5;
                } else {
                    fontSize = 16;
                }
                var percent = (fontSize/16)*100;
                $('textarea, input').css('font-size',percent+'%');
                $('.change-font-btn').blur();
            }
            </script>

위에 있는 input radio를  그 아래 select 박스로 바꾸고 싶은데 onclick이 아예 안먹히네요.

|

답변 1개 / 댓글 2개

채택된 답변
+20 포인트

select 태그는

input 과 짝이 아닌 

option과 짝입니다.

그리고,

select의 특성상 onclick 보다는 

onChange 를 사용하시는게 좋습니다.

클릭은 select box가 아래로 열릴때, 선택할때 반복적으로 작동되는 이벤트입니다.

onChange는 select의 선택된 값이 변경되때라서 적합하게 사용가능합니다.

답변에 대한 댓글 2개

네 감사합니다. 덕분에 잘 해결되었습니다.
도움받고 갑니다.^^

답변을 작성하려면 로그인이 필요합니다.