2016-11-01 2 views
0

부트 스트랩 datepicker가 있습니다. 입력 상자를 처음 클릭 할 때 show 이벤트가 실행되기를 원합니다. 그러나 사용자가 이전 및 다음 화살표로 달을 통과하는 경우 이벤트가 시작되는 것을 원하지 않습니다.날짜 표시기가 켜지면 show 이벤트가 실행되는 것을 방지합니다.

이것이 가능합니까? 당신은 당신이 먼저 입력 필드를 클릭하면 메시지가 표시됩니다 바이올린가 기록 얻을 실행하면

$('#sandbox-container input').datepicker({ 
    autoclose: true 
}); 

$('#sandbox-container input').on('show', function(e){ 
    console.log('show event'); 
}); 

(그 행동을하려는 경우). 그러나 이전 및 다음 화살표를 사용하면 해당 메시지가 표시됩니다.

JS 피들러는 여기 - http://jsfiddle.net/LcqM7/611/

답변

1

당신이 경우 현재 "상태"의 show 이미 "실행"을 체크해야합니다.

$('#sandbox-container input') 
    .on('show', function(e){ 
     if (! $(this).data('showrun')) { 
      console.log('show event'); 
      $(this).data('showrun', true); 
     } 
    }) 
    .on('hide', function(e){ 
     $(this).data('showrun', false); 
    }) 
    .on('changeMonth', function(e){ 
     console.log('change month event'); 
    }); 

그리고 작업 예 :
http://jsfiddle.net/k6b3yepb/

+0

완벽한이 내가 필요 정확히 - 건배 :) –

0

그것은 조금 잔인한입니다하지만 당신은 show 다음 jqueries one를 사용하여 다시 연결 바인딩을 해제 할 수있는 hide 이벤트를 활용할 수 있습니다.

http://jsfiddle.net/5dhkumko/

$('#sandbox-container input').datepicker({ 
    autoclose: true 
}); 

$('#sandbox-container input').one('show', showMethod); 

$('#sandbox-container input').on('hide', function(e) { 
    $('#sandbox-container input').off('show', showMethod).one('show', showMethod); 
}); 

function showMethod() { 
    console.log('show event'); 
}