简体   繁体   English

在ajax加载的内容上的jquery - datepicker(colorpicker等)

[英]jquery - datepicker (colorpicker etc) on ajax loaded content

Here is the thing. 这就是事情。 I have ajax loaded content (including form fields) and i need to add datepicker (colorpicker) to one of the new input fields. 我有ajax加载的内容(包括表单字段),我需要将datepicker(colorpicker)添加到其中一个新的输入字段。

Clearly $('input.datepicker').datepicker() doesn't work and .on() method doesn't seem to be working with load event. 显然$('input.datepicker').datepicker() datepicker()不起作用,而.on()方法似乎不适用于load事件。

I am not able to modify ajax handling script (so i can't add some callback - after successful ajax request). 我无法修改ajax处理脚本(所以我无法添加一些回调 - 成功的ajax请求后)。 Can you provide me some advices? 你能给我一些建议吗?

Thank you very much. 非常感谢你。

Use the .ajaxComplete() global handler: 使用.ajaxComplete()全局处理程序:

$(document).ajaxComplete(function(event, jqXhr, settings) {
     //maybe check whether you have to create the datePickers or not...
     $('input.datepicker').datepicker();
});

This jQuery global handler will be called whenever an AJAX request completes, regardless of which one is. 每当AJAX请求完成时,都会调用此jQuery全局处理程序,而不管是哪一个。 You can use the parameters passed to the callback to determine the concrete request and, perhaps, whether you need to rebuild your controls. 您可以使用传递给回调的参数来确定具体请求,也许还需要重建控件。

you can read more about the jQuery ajaxComplete handler if you're interested. 如果您有兴趣,可以阅读有关jQuery ajaxComplete处理程序的更多信息。

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

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