[英]JQuery Datepicker error after Postback with Ajax
my Datepicker works fine, but after postback it doesn't work any more. 我的Datepicker可以正常工作,但是回发后不再起作用。 I tried also pageLoad method but it still doesn't work.
我也尝试了pageLoad方法,但仍然无法正常工作。
I have a List of Items from database. 我有一个数据库项目列表。 If I click an item of the list, I get the information about it in a table from database (I used POST Method with Ajax).
如果单击列表中的一个项目,则会从数据库的表中获取有关该项目的信息(我将POST方法与Ajax一起使用)。
Jquery: jQuery的:
<script>
$(function() {
var pickerOpts = { dateFormat: $.datepicker.ATOM };
$("#datepicker").datepicker(pickerOpts);
});
</script>
Textfield: 文本域:
echo("<input type='text' id='datepicker' value='$db[deadline]'>");
I've googled for hours but found nothing that worked for me. 我已经搜索了几个小时,但没有发现对我有用的东西。
EDIT NOTE: Errors after trying Rahil Wazir's help: 编辑提示:尝试拉希尔·瓦齐尔的帮助后出现错误:
Use this: 用这个:
<script>
$(function() {
var pickerOpts = { dateFormat: $.datepicker.ATOM }; //Place this inside below .on handler if this also updates.
$(document).on('focus', '#datepicker', function(e){
$(this).datepicker(pickerOpts);
});
});
</script>
You have to use $(document).on
handler when dom updates. dom更新时必须使用
$(document).on
处理程序。 And add event focus
to trigger the datepicker handler. 并添加事件
focus
以触发datepicker处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.