2013-03-04 136 views
0

我已經向jquery datepicker插件添加了一些基本的工具提示,但在更改月份後,事件不再綁定到它們的選擇器。我如何在月份更改時重新綁定這些事件?Jquery tooltip ON事件不會在datepicker月份更改後觸發

下面是我正在使用的減少版本。

<script> 

$(function() { 
    $("#scene").datepicker(); 
    var evtd = { 
     March312013: {title: "Ladies Night"}, 
     March302013: {title: "Lilly Allen Tribute Band"} 
    } 

    $(".ui-state-default").on("mouseenter", function(e) { 
     var month = $(".ui-datepicker-month").text(); 
     var year = $(".ui-datepicker-year").text(); 
     var day = $(this).text(); 
     ix = month + day + year; 
     if(typeof(evtd[ix])!="undefined") 
     { 
      var html = '<h5>'+evtd[ix]["title"]+'</h5>'; 
      var eleft = $(this).position().left; 
      var etop = $(this).position().top; 
      $("#tt").html(html).css({ 
       left: Math.max(eleft-($(this).width()/2),0), 
       top: Math.max(etop+$(this).height()+7,0) 
      }).show(); 
     } 
    }).mouseleave(function(){ 
     $("#tt").hide(); 
    }); 
}); 

</script> 
<style> 
.nm{ 
    margin:0; 
} 

#tt{ 
    max-width:250px; 
    position:absolute; 
    border:1px solid black; 
    background-color:#E9EAEE; 
    padding:8px; 
    display:none; 
    -webkit-border-radius: 6px; 
    -moz-border-radius: 6px; 
    border-radius: 6px; 
    font-family:Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; 
} 
</style> 

<div id="scene">MobeScene Events</div> 
<div id="tt"></div> 
+0

嘗試在$(document).ready()中寫入你的函數。 – Pratik 2013-03-04 13:36:38

回答

1

試圖將綁定事件是這樣的:

$(document).on("mouseenter",".ui-state-default",function(e){ 
    //Your stuff 
}); 

進一步吃茶見this answer