select 박스 dom 으로 제어 > script

본문 바로가기

script

select 박스 dom 으로 제어

작성일 07-06-27 09:15

페이지 정보

작성자서방님 조회 400회 댓글 0건

본문

선택한 option 엘리먼트의 text와 value를 추출하기 위한 두 가지 형태의 DOM 스크립트 작성 방법을 비교하여 최적의 방법을 생각해 보고자 합니다.


--- 방법: 1   ---------------------
<script type="text/javascript">
<!--

 for (m = 0; m < pointFileSplit.length; m++)
 {
  var pointCount = m.toString(10);
  var optionID = "opt" + pointCount;
  var optionCheck = document.getElementById (optionID);

  if (optionCheck.selected == true) //option을 선택하면 true
  {
   var selectValue = optionCheck.value;

   var selectText = optionCheck.text;
  }
 }
//-->
</script>


--- 방법: 2   ---------------------
<script type="text/javascript">
<!--

 var selectElement = document.getElementById("selectID");

 var selectValue = selectElement.value;

 var selectText = selectElement.options[selectElement.selectedIndex].text;
//-->
</script>
----------------------------------


상기 두 가지 코딩 방법에서 아래의 코딩 방법이 간단하게 option의 value, text를 추출할 수 있다.

 

댓글목록

등록된 댓글이 없습니다.

전체 846건 43 페이지
게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기