jQuery的日期选择器不工作的AJAX生成的输入字段 [英] jQuery date picker not working on ajax-generated input field

查看:130
本文介绍了jQuery的日期选择器不工作的AJAX生成的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是通过Ajax从服务器侧生成的,并插入到当前页面的输入字段。我的问题是:jQuery的日期选择器不工作时通过Ajax生成它的输入栏,但它的工作原理,当现场直接放置在页面

I have an input field that is generated via Ajax from the server-side, and inserted into the current page. My problem is: the jQuery date picker is not working on the input field when it is generated via Ajax, but it works when the field is directly placed in the page.

下面,我包括我的code的缩小版本。

Below, I include a scaled-down version of my code.

HTML code:

HTML code:

<form id="user-form"></form>

和这里的jQuery的code,它是应该激活日期选择器就可以了。

And here's the jQuery code that's supposed to activate the datepicker on it.

$.ajax({
    type: "GET",
    url: "/inputfield-loader.php" ,
    success: function(data) {
        $('#user-form').html(data);
        $("#datefield").datepicker();
    } 
});

而这里的 inputfield-loader.php

<input type="text" name="firstname" id="firstname"></div>
<div><input type="text" name="email" id="email"></div>
<div><input type="text" name="birthdate" id="datefield"></div>
<div><input type="submit"></div>

正如我已经说过,这个效果很好,如果输入字段只是硬codeD插入页面。但是,当插入到DOM作为Ajax调用的返回字符串,日期选择器不再工作。

As I already said, this works well if the input field is just hard-coded into the page. But when inserted into the DOM as the return string of an Ajax call, the date picker no longer works.

任何人有任何想法如何解决这一问题?

Anybody has any idea how to fix this?

注意我已经更新了问题,包括codeS显示到底发生了什么,因为每个注释通过@AkshayKhandelwal

NOTE I have updated the question to include codes showing exactly what is happening, as per the comment by @AkshayKhandelwal

推荐答案

试试这样

success: function() {
  $('#datefield').datepicker();
}

这篇关于jQuery的日期选择器不工作的AJAX生成的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆