gpt4 book ai didi

javascript - jquery 在动态元素上调用日期选择器

转载 作者:行者123 更新时间:2023-11-29 21:52:11 27 4
gpt4 key购买 nike

我试图在动态创建的元素上调用日期选择器,但不起作用。我知道我的格式不正确。谁知道怎么做?

    $("body").on('click', '.startNew', function() {
$(".startNew").datepicker({
dateFormat : "yy-mm-dd 00:00:00",
numberOfMonths: 2,
onSelect: function(selected) {
$(".endNew").datepicker("option","minDate", selected)
}
});
});
$("body").on('click', '.endNew', function() {
$(".endNew").datepicker({
dateFormat : "yy-mm-dd 00:00:00",
numberOfMonths: 2,
onSelect: function(selected) {
$(".startNew").datepicker("option","maxDate", selected)
}
});
});

最佳答案

已更新。尝试改变(body -> document; click -> focus)

来自

$(body).on('click',".startNew", function(){
$(".startNew").datepicker({

$(body).on('click',".endNew", function(){
$(".endNew").datepicker({

$(document).on('focus',".startNew", function(){
$(this).datepicker({

$(document).on('focus',".endNew", function(){
$(this).datepicker({

工作 FIDDLE

HTML

Start: <input class='endNew'><br/><br/>
End: <input class='startNew'>

JS

$(document).on('focus',".startNew", function(){
$(this).datepicker({
dateFormat : "yy-mm-dd 00:00:00",
numberOfMonths: 2,
onSelect: function(selected) {
$(".endNew").datepicker("option","minDate", selected)
}
});
});


$(document).on('focus',".endNew", function(){
$(this).datepicker({
dateFormat : "yy-mm-dd 00:00:00",
numberOfMonths: 2,
onSelect: function(selected) {
$(".startNew").datepicker("option","maxDate", selected)
}
});
});

关于javascript - jquery 在动态元素上调用日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28575014/

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