테스트 사이트 - 개발 중인 베타 버전입니다

select 선택에 따라 테두리 색상 변경

· 7년 전 · 5112 · 3

<style>
.ex-select {padding:0.5em; border-radius:0.5em; border:1px solid;}
</style>

<select class="ex-select">
    <option value="red" data-color="red">red</option>
    <option value="green" data-color="green">green</option>
    <option value="blue" data-color="blue">blue</option>
    <option value="tomato" data-color="tomato">tomato</option>
    <option value="lightblue" data-color="lightblue">lightblue</option>
</select>

<script>
$(function() {
    $('.ex-select').change(function(e) {
        var $this = $(this);
        var c = $this.find('option:selected').data('color');
        $this.css({'color':c, 'border-color': c});
    });
    $('.ex-select').each(function() {
        var $this = $(this);
        $this.trigger('change');
        $this.find('option').each(function() {        
            $(this).css('color',$(this).data('color'));
        });
    });
});
</script>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 3개

7년 전
감사합니다.
7년 전
좋은 자료 감사합니다~
7년 전
좋은 자료 감사합니당

게시글 목록

번호 제목
15895
15894
15893
15888
15887
15886
15885
jQuery .end()
15884
15883
jQuery .each()
15882
jQuery .die ()
15881
15880
15878
15877
15876
15874
15873
15872
15871
15866
15865
15864
15863
15862
15861
15859
15858
15857
15856
15855