2013-11-23 3 views
0

작은 이미지를 클릭 할 때 datepicker를 렌더링하고 날짜를 선택한 다음 선택한 날짜를 사용하여 선택한 날짜를 기준으로 연도, 월 및 일의 선택 요소 그룹을 채 웁니다. onSelect 부분을 알아 냈고 select 요소의 옵션에 선택한 날짜를 적용했습니다.jQuery datepicker 숨기기

내 문제는 datepicker가 날짜 선택을 닫지 않는다는 것입니다. 거기에 머물러 있습니다. hide() 메서드를 호출하면 이미지 (스팬 요소의 일부)도 숨겨집니다.

$("#pickupCalendar").click(function() { 
    $("#pickupCalendar").datepicker({ 
     dateFormat: 'dd-mm-yy', 
     onSelect: function (dateText, inst) { 
      //code to fill the other elements with the selected date goes here 
      $("#pickupCalendar").datepicker().hide(); //<-- hides the image (span element along with the datepicker) 
     } 
    }); 
}); 
+0

왜 스팬 내부의 이미지가 있나요? 클릭 핸들러에서 날짜 선택 도구를 정의하는 이유는 무엇입니까? jsfiddle에서 데모를 제공 할 수 있습니까? –

+0

나는 스팬 요소에 datepicker를 첨부 할 수 있다는 것을 알고 있기 때문에. 다음은 이미지를 버튼으로 대체하는 바이올린입니다. http://jsfiddle.net/Ysxv3/ – Chinmay

답변

1

HTML 마크 업이 변경되어 요소를 쉽게 타겟팅 할 수 있습니다.

<span id="pickupCalendar"></span><button>Button</button> 

    $("button").click(function() { 
     $("#pickupCalendar").show(); 
     $("#pickupCalendar").datepicker({ 
      dateFormat: 'dd-mm-yy', 
      onSelect: function (dateText, inst) { 
       //code to fill the other elements with the selected date goes here 
       $("#pickupCalendar").datepicker().hide(); 
      } 
     }); 
    }); 

FIDDLE

+0

우수! 나중에 datepicker를 만들지 않은 버전을 수정했습니다. 이것이 우리의 해결책입니다 : http://jsfiddle.net/Ysxv3/4/ 변경 사항을 보았습니다. 방향 주셔서 감사합니다! :) – Chinmay

+0

예, 컨셉에 맞게 컨셉을 변경하십시오! 다행히 도울 수있어. – Sebsemillia

+0

나는 왜 요소가 숨겨진 지 궁금해. "파괴"는 비슷하게 작용합니다. – Chinmay

0

당신이 시도 할 수 :

<span id="pickupCalendar"><img src="/images/calendar.png"></img></span> 

이 스크립트는 다음과 같습니다이 내 HTML 코드?

$("#pickupCalendar").click(function() { 
    $("#pickupCalendar").datepicker({ 
     dateFormat: 'dd-mm-yy', 
     onSelect: function (dateText, inst) { 
      //code to fill the other elements with the selected date goes here 
      $("#pickupCalendar").datepicker().hide(); 
      $("#pickupCalendar img").hide(); 
     } 
    }); 
}); 
+0

음, 작동하지 않고 작동하지 않습니다. 바이올린을주의하십시오. – Chinmay