• 회원가입
  • 로그인
  • 구글아이디로 로그인

[HTML_Objects] JS - <select> 객체 ★★ - 선택메뉴 (= select메뉴 = select태그 = 실렉트태그/셀렉트태그) ※ 검색포털링크/SNS검색링크

목차
  1. <select> 객체 정의 - 선택 메뉴
  2. <select> 객체 구문
  3. <select> 객체 예제 - 접근
  4. <select> 객체 예제 - 생성
  5. <select> 객체 집합
  6. <select> 객체 속성
  7. <select> 객체 메서드
  8. <select> 객체 예제 - 링크 이동
  9. <select> 객체 예제 - 검색 포털 선택해 검색

 

<select> 객체 정의 - 선택 메뉴

 

HTML <select> 태그(요소) 의미.

 

 

<select> 객체 구문

 

[접근]

var x = document.getElementById("요소ID");

또는,

var x = document.getElementById("폼요소ID").elements;

 

[생성]

var x = document.createElement("SELECT");

 

 

<select> 객체 예제 - 접근

 


<select id="hz" size="4">

  <option>HTML</option>

  <option>CSS</option>

  <option>PHP</option>

  <option>SQL</option>

</select>


<button onclick="homzzang()">클릭</button>


<p id="demo"></p>


<script>

function homzzang() {

  var x = document.getElementById("hz").length;

  document.getElementById("demo").innerHTML = x;

}

</script>


결과보기

 

<select> 객체 예제 - 생성

 

<button onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  var x = document.createElement("SELECT");

  x.setAttribute("id", "hz");

  document.body.appendChild(x);


  var z = document.createElement("option");

  z.setAttribute("value", "HTML");

  var t = document.createTextNode("HTML - 구조");

  z.appendChild(t);

  document.getElementById("hz").appendChild(z);

}

</script>

 

결과보기

 

<select> 객체 집합

 

options 

드롭다운 목록의 모든 옵션 모음 반환.

 

 

<select> 객체 속성

 

autofocus

페이지 로드 될 때 드롭다운목록이 자동으로 focus 가져야하는지 여부 설정/반환.

 

disabled

드롭 다운 목록의 비활성화 여부 설정/반환.

 

form

드롭다운목록이 포함된 양식에 대한 참조 반환.

 

length

드롭다운목록에서 <option> 요소개수 반환.

 

multiple

드롭다운목록에서 둘 이상의 옵션을 선택할 수 있는지 여부 설정/반환.

 

name

드롭다운목록의 name 속성값 설정/반환.

 

selectedIndex

드롭다운목록에서 선택한 옵션의 인덱스 설정/반환.

 

size

드롭 다운 목록에 표시되는 옵션개수 설정/반환.

Chrome・Safari에서는 size = "2" 및 size = "3"에 대해 정상작동 안 할 수도 있음.

 

type

드롭다운목록이 있는 양식 요소 유형을 반환.

 

value

드롭다운목록에서 선택한 옵션의 값을 설정/반환.

 

 

<select> 객체 메서드

 

add()

드롭다운목록에 옵션 추가.

 

checkValidity()

유효성 체크

 

remove()

드롭다운목록에서 옵션 제거.

 

※ <select> 객체는 표준 속성/메서드/이벤트 지원.

 

<select> 객체 예제 - 링크 이동

[현재창 이동]

 

<select onchange="if(this.value) location.href=(this.value);">

    <option value="">링크 선택</option>

    <option value="https://homzzang.com">홈짱닷컴</option>

</select>

 


[새창 이동]

 

<select onchange="if(this.value) window.open(this.value);">

    <option value="">링크 선택</option>    

    <option value="https://homzzang.com">홈짱닷컴</option>

</select>

 

결과보기


PS. 링크 선택 후 클릭해야 이동


<script>

function goUrl(f) {

 var url = f.url.value;

 if(url) window.open(url)

}

</script>


<form onsubmit="return goUrl(this)">

    <select name="url">

        <option>링크 이동</option>

        <option value="http://homzzang.com">홈짱닷컴</option>

    </select>

    <input type="submit" value="GO">

</form>

 

결과보기


<select> 객체 예제 - 검색 포털 선택해 검색

 

<form action="#" method="get">

    <select id="search-engine">

        <option value="https://search.naver.com/search.naver?query=">네이버</option>

        <option value="https://search.daum.net/search?w=tot&q=">다음</option>

        <option value="https://search.daum.net/nate?thr=sbma&w=tot&q=">네이트</option>

        <option value="https://search.zum.com/search.zum?method=uni&option=accu&rd=1&query=">줌</option>

        <option value="https://www.youtube.com/results?search_query=">유튜브</option>

        <option value="https://www.instagram.com/explore/tags/">인스타그램</option>

        <option value="https://www.facebook.com/search/top/?q=">페이스북</option>

        <option value="https://twitter.com/search?q=">트위터</option>

    </select>

    <input type="text" id="search-query">

    <button type="submit" onclick="submitSearch()">검색</button>

</form>


<script>

function submitSearch() {

    const engine = document.getElementById("search-engine").value;

    const query = document.getElementById("search-query").value;

    const url = engine + encodeURIComponent(query);

    //window.location.href = url; // 현재창

    window.open(url, '_blank').focus(); // 새탭

}

</script>


 

결과보기



분류 제목
HTML_Objects JS - <input type="reset"> 객체 - reset타입 input태그 (= 인풋리셋태그) ※ …
HTML_Objects JS - <input type="search"> 객체 - search타입 input태그 (= 인풋서치태그) …
HTML_Objects JS - <input type="submit"> 객체 - submit타입 input태그 (= 인풋서브미트태그…
HTML_Objects JS - <input type="text"> 객체 ★ - text타입 input태그 (= 인풋텍스트태그) ※…
HTML_Objects JS - <input type="time"> 객체 - time타입 input태그 (= 인풋타임태그) ※ 시간…
HTML_Objects JS - <input type="url"> 객체 - url타입 input태그 (= 인풋유알엘태그) ※ 웹주소…
HTML_Objects JS - <input type="week"> 객체 - week타입 input태그 (= 인풋위크태그) ※ 주 …
HTML_Objects JS - <kbd> 객체 - 키보드입력키 (= kbd태그 = 키보드태그)
HTML_Objects JS - <label> 객체 ★ - input태그꼬리표 (= label태그 = 라벨태그/레이블테그) (HTM…
HTML_Objects JS - <legend> 객체 - fieldset 제목/설명 (= legend태그 = 레전드태그) (HTML…
HTML_Objects JS - <li> 객체 ★ - 리스트목록 (= li태그 = 리스트태그) (HTML5수정)
HTML_Objects JS - <link> 객체 ★ - 외부소스연결 (= link태그 = 링크태그) (HTML5수정)
HTML_Objects JS - <map> 객체 - 이미지맵 (= map태그 = 이미지맵태그) ※ 이미지 특정 부분에 링크
HTML_Objects JS - <mark> 객체 - 형광펜칠하기 (= mark태그 = 마크태그) (HTML5추가, IE9)
HTML_Objects JS - <menu> 객체 - 명령어메뉴목록 (= menu태그 = 메뉴태그) ※ 아직 지원X
HTML_Objects JS - <menuitem> 객체 - 마우스오른쪽 팝업메뉴 (= menuitem태그 = 메뉴아이템태그) (H…
HTML_Objects JS - <meta> 객체 ★ - 메타정보 (= meta태그 = 메타태그) (HTML5수정) + 모바일주소창…
HTML_Objects JS - <meter> 객체 - 게이지바 (= meter태그 = 미터태그) : (IE:지원X)
HTML_Objects JS - <nav> 객체 ★ - 네비게이션링크모음 (= nav태그 = 네브태그 = 네비게이션태그) (IE9…
HTML_Objects JS - <object> 객체 - 미디어삽입 (= object태그 = 어브젝트태그)
4/6
목록
찾아주셔서 감사합니다. Since 2012