简体   繁体   English

如何比较texbox与datepicker

[英]How to compare texbox with datepicker

I just need to validate a texbox with the year yyyy with a datepicker dd-mm-yyyy. 我只需要使用datepicker dd-mm-yyyy验证带有yyyy年份的texbox。 is there any way to do this using javascript? 有没有办法用javascript做到这一点? Thanks 谢谢

This is how I would do it using JQuery: 这是我如何使用JQuery做到这一点:

$(function() {
     $("#your_datepicker").datepicker({
           onSelect: function(dateText, inst) {
              var startDate = new Date(dateText);
              var selectedYear = startDate.getFullYear(); // selected year
              var textbox = document.getElementById("txtBox").value  //you might need to cut the string depending on how the user should enter the year in the textbox
              if(textbox === selectedYear{
                 // Do what you need to
              }
           }
     });
});

I hope I understood your question correctly, if not you should give me additional information.. 我希望我能正确理解你的问题,如果没有,你应该给我更多信息..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM