2010-01-20 4 views
4

나는 두 개의 날짜를 가진 select 요소를 가지고 있지만 다음과 같이 달력 아이콘을 표시하는 다음 코드를 가질 수 있도록 datepicker에서 날짜를 선택할 수도 있습니다. 선택 필드.jQuery ui.datepicker on 'select'element

<select name="birthday" > 
    <option value="${merge0.birthday}">${merge0.birthday}</option> 
    <option value="${merge1.birthday}">${merge1.birthday}</option>       
</select> 
<input type="hidden" id="bday_icon" /> 

그런 다음,이

$("#bday_icon").datepicker(
      { 
       changeMonth: true, 
       changeYear: true, 
       showOn: 'button', 
       buttonImage: 'cal/images/calendar.gif', 
       buttonImageOnly: true, 
       onSelect: function(dateText, inst) { 
        var field = document.getElementsByNameByName("birthday"); 
        var opt = document.createElement('option'); 
        opt.text = dateText; 
        opt.value = dateText; 
        field.add(opt, null); 
      } 
      }); 

함수 onSelect를이 선택 html 요소에 새로운 옵션을 추가하지 않겠

내 날짜 선택기 스크립트입니다? 그것이 틀린 것을 당신은 볼 수 없습니까?

감사합니다.

업데이트 1 : 그들이 당신의 기능의 일부가 아니라면 $('<option selected/>')

답변

3

, 나는 ':

onSelect: function(dateText, inst) { 
     var opt = $('<option />').attr('value', dateText).text(dateText); 
     $('select[name=birthday]').append(opt); 
     } 

만 새로운 옵션이 너무처럼 편집 선택으로 내가 표시 할 필요가 있다고 발언 완벽한 작품 나는 정말로 무엇을 .add()getElementsByNameByName()인지 모르겠다. jQuery API에서 add을 찾지 못하는 것 같습니다. 나를 위해

onSelect: function(dateText, inst) { 
    var opt = $('<option />').attr('value', dateText).text(dateText); 
    $('select[name=birthday]').append(opt); 
} 

작품 : jQuery를 위젯으로 작업 할 때

또한, 내가 jQuery를 선택기를 사용하는 것을 선호합니다.

+0

내가 필요한만큼 완벽하게 작동합니다. – framara