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

본문 바로가기




WEBDEV


사이트 내 전체검색


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

페이지 정보

작성자 최고관리자 댓글 0건 조회 2,604회 작성일 18-11-26 13:26

본문

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

댓글목록

등록된 댓글이 없습니다.



개인정보처리방침
서비스이용약관
모바일버전
그누보드5
Copyright © 소유하신 도메인. All rights reserved.