• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 WebComponent custom elements 질문 (수정)

WebComponent custom elements 질문 (수정)

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #27843

    코딩초보
    참가자

    class TimeInput extends HTMLElement {

                  connectedCallback(){
                    let sele = document.createElement('select');
                    sele.setAttribute('class', 'xxx');
                    sele.setAttribute('name', 'aaa');
                   
                    this.appendChild(sele)
                   let opt= document.createElement('option');
                    for(var i=0; i<24; i++){
                      let opt= document.createElement('option');
                    opt.value = String(i).padStart(2, 0);
                    opt.text = String(i).padStart(2, 0)+'시';
                    sele.appendChild(opt)
                    }
                   
                  }
                }

                customElements.define('time-input', TimeInput)

    이런식으로 커스텀 한 후 <time-input></time-input>을 해놓으면

    <select class="xx" name="aa"/> ... 이 만들어지는 것은 알았습니다. 그러면 저 for문 안에서 option에 삼항연산자 자체를 붙이려고한다면 어떻게 해야하나요?  최종적으로 <option (abc==ex ? 'selected' : '') />를 구현하고 싶습니다

    #27855

    코딩초보
    참가자

    아 해결되었습니다 그것보다 다른걸 여쭈고싶은데 <time-input class="aa"> 처럼 클래스 aa를 선언하고 이 클래사 aa가 select 태그에만 class가 들어가게 할 수 있나요?

    #27869

    codingapple
    키 마스터

    <time-input class="aa"> 이렇게 사용시 

    class TimeInput 안에서 this.getAttribute('class') 하면 aa가 출력됩니다

    그걸 원하는곳에 넣으면 됩니다

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠