gpt4 book ai didi

javascript - jQuery.val() 仅在带有日期选择器的第二个事件上返回值

转载 作者:行者123 更新时间:2023-11-29 23:04:40 33 4
gpt4 key购买 nike

我正在使用 jQuery UI 的日期选择器处理一个(遗留)项目。我需要验证元素中输入的日期距离当前日期至少 24 小时。我在 blur 上抓取 datepicker 元素的值来验证它。问题是尝试获取应用了日期选择器的输入的值的行为不一致。 .val() 仅返回第二个模糊事件的值,然后返回该事件之前的模糊事件的值。使我抓狂。

标记:

<form action="" method="GET" novalidate="novalidate" class="form">
<fieldset>
<legend>Entry Date/Time</legend>

<label for="ad" class="screen-reader-text">Entry Date</label>
<span class="fa fa-calendar"></span>
<input type="text" id="entry-date" name="ad" placeholder="March 4, 2019" autocomplete="off">
</fieldset>

<div class="submit-wrapper">
<input type="submit" class="parking-submit" value="Submit">
</div><!--ends submit-wrapper-->
</form>

JS:

  jQuery(document).ready(function($){
$('.form input[type=text]').datepicker({
minDate: -0,
nextText: '>>',
prevText: '<<',
dateFormat: 'M dd, yy'
});

$('#entry-date').blur(function(){
var now = new Date();
console.log(now);
var tomorrow = new Date(now.getTime() + 86400000); //1 day in ms
console.log(tomorrow);
var dateGiven = $('#entry-date').val();
console.log('Set value is' + dateGiven);
});
});

这是 a pen显示问题。

感谢任何帮助。

最佳答案

使用变化代替模糊。

   $('#entry-date').change(function(){
var now = new Date();
console.log(now);
var tomorrow = new Date(now.getTime() + 86400000); //1 day in ms
console.log(tomorrow);
var dateGiven = $('#entry-date').val();
console.log('Set value is' + dateGiven);
});

关于javascript - jQuery.val() 仅在带有日期选择器的第二个事件上返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54994438/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com