简体   繁体   English

.load()之后无法重新应用jQuery Datepicker

[英]jQuery Datepicker Can't be Reapplied after .load()

My HTML is setup similar to this this: 我的HTML的设置与此类似:

<div id='header'>
</div>
<div id='main'>
</div>
<div id='footer'?
</div>

Rather than change pages, when the user wants to navigate to a new area I simply load the HTML using $("#main").load("newFile.html"). 当用户想导航到一个新区域时,我只需要使用$(“#main”)。load(“ newFile.html”)来加载HTML,而不是更改页面。 On one file, I have a text input field that I apply a datepicker to. 在一个文件上,我有一个文本输入字段,将日期选择器应用于该文本输入字段。 The datepicker field works fine initially, but if I try to reload the "main" no amount of calls to add a datepicker to that field will take. datepicker字段最初可以很好地工作,但是如果我尝试重新加载“ main”,则不会进行向该字段添加日期选择器的调用。 I am simply adding the datepicker via: 我只是通过以下方式添加日期选择器:

$("#myInput").datepicker();

If I only call the above once on initial load and don't try to reapply, it doesn't remember the original datepicker call, so it's not the repeat application of the above code. 如果我在初始加载时仅调用一次上述内容,并且不尝试重新应用,则它不会记住原始的datepicker调用,因此它不是上述代码的重复应用。 What can I do to make sure the datepicker always works? 如何确保日期选择器始终可用?

I've had a similar issue with datepickers being dynamically loaded. 我有一个类似的问题,与日期选择器动态加载。 There I had to resort to an ugly hack that relies on the inner workings of the datepicker plugin. 在那里,我不得不依靠datepicker插件的内部运作方式进行丑陋的破解。 As in

$(".ui-datepicker-trigger").remove();
$(".datepicker").removeClass('hasDatepicker');
$(".datepicker").datepicker();

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

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