简体   繁体   English

第一次加载页面时jQuery Datepicker可以,但是此后失败

[英]jQuery Datepicker okay on first load of a page but fails thereafter

This is the second time I have asked this question. 这是我第二次问这个问题。 Neither the responses I received initially nor any of the myriad of other answers to similar questions have helped me to solve the problem. 我最初收到的答复或类似问题的无数其他答案都没有帮助我解决问题。

The problem is that once a datepicker object is initialized, a second initialization causes it to fail. 问题在于,一旦初始化了日期选择器对象,第二次初始化将使其失败。 I have tried all sorts of blurring and destroying but nothing has worked for me. 我尝试了各种模糊和破坏,但没有任何效果对我有用。

Please take a look at this simple page which demonstrates the problem 请看一下显示问题的简单页面

Here is the javascript for the page that contains the datepicker input elements... 这是包含datepicker输入元素的页面的javascript ...

$(document).ready (function(){
     sp = " ";
     lf = '\n'


  $(function (){
     $("input#datepicker").datepicker(); 
     $("input#datepicker2").datepicker();   
  })


})// document ready

I would truly appreciate any help to get this working. 我真的很感激任何帮助,以使这项工作。 I've already spent about eight hours with no success. 我已经花了大约八小时没有成功。

Thanks, 谢谢,

-dmd- -dmd-

Your code is obsolete. 您的代码已过时。 you got a document ready function inside of an document ready function ( $(function(){}) is a shorthand of $(document).ready(function(){}) . But this isn't the Problem. Use the following code in your divtest.html and remove the calls in datepicker.html: 您在文档准备功能内部获得了文档准备功能( $(function(){})$(document).ready(function(){})的简写。但这不是问题,请使用以下命令divtest.html中的代码,并删除datepicker.html中的调用:

$(function(){
  $(document).on('DOMNodeInserted','input#datepicker,input#datepicker2', function(){
    $(this).datepicker();
  });
}

Finally, I have a solution and it is simple. 最后,我有一个解决方案,它很简单。

On the datepicker page, before initializing datepicker, add this line 在日期选择器页面上,在初始化日期选择器之前,添加以下行

$('#ui-datepicker-div').remove();

then 然后

$("input#datepicker").datepicker(); 
$("input#datepicker2").datepicker();

This works for me and I truly hope it works for everyone else who has been bogged down with the issue. 这对我有用,我真正希望它对陷入困境的其他所有人也有用。

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

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