Javascript 打开日期选择器的条件

Javascript 打开日期选择器的条件,javascript,jquery,jquery-ui,jquery-ui-datepicker,preventdefault,Javascript,Jquery,Jquery Ui,Jquery Ui Datepicker,Preventdefault,我希望我的datepicker仅在以下条件下打开:在本例中,存在一个类,下面是不起作用的代码: $('.ui-datepicker-trigger').click(function(e){ if ($(this).hasClass('disableDatepicker')) { e.preventDefault(); } }); 谢谢 尝试使用“not”选择器或方法 选择器 $('.ui-datepicker-trigger:not(.disableDatepi

我希望我的datepicker仅在以下条件下打开:在本例中,存在一个类,下面是不起作用的代码:

$('.ui-datepicker-trigger').click(function(e){
    if ($(this).hasClass('disableDatepicker')) {
        e.preventDefault();
    }
});

谢谢

尝试使用“not”选择器或方法

选择器

$('.ui-datepicker-trigger:not(.disableDatepicker)').click(function(e){
    //your code
});
方法

$('.ui-datepicker-trigger').not('.disableDatepicker').click(function(e){
    //your code
});

这与您所做的类似,您可以在这里找到我为您创建的一个实例()

或者检查自解释的代码:

$(document).ready(function(){

  $(".click").on("click", function(e){

     if ( $(this).hasClass("prevent") ) {
       console.log("hasClass prevent!");
       e.preventDefault();
     }

  });

});
html:

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta name="description" content="" />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

  <a class="click" href="//google.com" target="_blank">Click1</a>
    <a class="click prevent"  href="//google.com" target="_blank">Click2</a>

</body>
</html>

JS-Bin
希望这有帮助

这应该是个好办法

$("input").datepicker({ 
         beforeShow: function(a,b){ 
             if ($(this).hasClass('disableDatepicker')) return false;  
         } 
});

但我认为您需要启用/禁用某些事件