2013-03-04 137 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