JQuery datepicker not working after ajax call(JQuery日期选择器在ajax调用后不起作用)
问题描述
我有以下代码
<头>//包括所有jquery相关的东西..这里没有显示头部><身体><按钮 id = 'btn'/><?php echo file_get_contents('my_ajax_stuff.php');?><脚本>$('.datepicker').datepicker({dateFormat: "dd-mm-yy"});$('#btn').click(function() {$.ajax({类型:获取",url: "my_ajax_stuff.php" ,成功:功能(响应){$('#ct').html(响应);/*添加以下行来解决这个问题..但没有奏效*///$( ".datepicker" ).datepicker({dateFormat: "dd-mm-yy"});} ,错误:函数(){$('#ct').html("获取数据时出现问题,请重试");}});});
页面
<块引用>my_ajax_stuff.php
包含一个类 = 'datepicker' 的 jquery ui datepicker.在第一次加载时,datepicker 可以工作.但是当我再次单击按钮重新加载时,内容被新内容替换.但是 datepicker 不起作用.我已经尝试在 ajax 成功处理程序中初始化日期选择器,如您所见.但它也失败了.这是什么问题.如何解决???
你需要重新初始化Ajax成功中的日期选择器
$('.datepicker').datepicker({dateFormat: "dd-mm-yy"});$('#btn').click(function() {$.ajax({类型:获取",url: "my_ajax_stuff.php" ,成功:功能(响应){$('#ct').html(响应);$( "#datepicker" ).datepicker();/*添加以下行来解决这个问题..但没有奏效*///$( ".datepicker" ).datepicker({dateFormat: "dd-mm-yy"});} ,错误:函数(){$('#ct').html("获取数据时出现问题,请重试");}});});I have the following code
<html>
<head>
//included all jquery related stuff ..not shown here
</head>
<body>
<button id = 'btn' />
<div id = 'ct'>
<?php echo file_get_contents('my_ajax_stuff.php'); ?>
</div>
</body>
<script>
$('.datepicker').datepicker({dateFormat: "dd-mm-yy"});
$('#btn').click(function() {
$.ajax({
type: "GET",
url: "my_ajax_stuff.php" ,
success: function(response) {
$('#ct').html(response);
/*added following line to solve this issue ..but not worked*/
//$( ".datepicker" ).datepicker({dateFormat: "dd-mm-yy"});
} ,
error: function () {
$('#ct').html("Some problem fetching data.Please try again");
}
});
});
</script>
</html>
The page
my_ajax_stuff.php
contains a jquery ui datepicker with class = 'datepicker'.On the first load the datepicker works.But when I click on the button to reload it again , the contents are replaced with new contents.But the datepicker is not working.I have tried initialising the datepicker inside the ajax success handler ,as you see.But it also failed.What is the issue.How can it be solved???
You need to reinitialize the date picker in Ajax success
$('.datepicker').datepicker({dateFormat: "dd-mm-yy"});
$('#btn').click(function() {
$.ajax({
type: "GET",
url: "my_ajax_stuff.php" ,
success: function(response) {
$('#ct').html(response);
$( "#datepicker" ).datepicker();
/*added following line to solve this issue ..but not worked*/
//$( ".datepicker" ).datepicker({dateFormat: "dd-mm-yy"});
} ,
error: function () {
$('#ct').html("Some problem fetching data.Please try again");
}
});
});
这篇关于JQuery日期选择器在ajax调用后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JQuery日期选择器在ajax调用后不起作用
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
