如何克隆jQuery Datepicker输入字段 [英] How to clone jQuery Datepicker input field

查看:159
本文介绍了如何克隆jQuery Datepicker输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要克隆一个jQuery datepicker输入字段,使用on语句附加一个datePicker。

I need to clone a jQuery datepicker input field attached a datePicker to it using the on statement.

$('form').on('click', '.datepicker', function(){
         $(this).datepicker({'changeMonth': true, 'changeYear': true, 'dateFormat': 'MM dd', 'yearRange': "<?php echo date('Y') ?>:<?php echo date('Y') + 1 ?>"}).focus();
    });

然后在克隆输入文件之前,我正在使用

Then before cloning the input filed, I am destroying the datepicker using

$(".datepicker").datepicker('destroy').removeClass('hasDatepicker');

但是,附加到新克隆输入的datepicker仍然是乱码的原始输入字段..

But still the datepicker that is being attached to then newly cloned input is messing with original input field...

任何人都可以帮助我解决这个问题?

Can anybody please help me on this topic?

推荐答案

尝试这个

var $clone=$(".datepicker").clone();
$clone.datepicker("destroy");
$clone.removeAttr("id");
$clone.datepicker();
$('form').append($clone);

当您复制一行时,它会复制每件事物
以及何时添加日期选择器再次通过ID调用输入,您必须删除该ID,以便下一个日期戳可以为输入分配一个新的id:)

when you clone a row it copies every thing, and when the date picker is added again it calls the input by id, you must remove the id so that the next datepicker can assign a new id to the input :)

这篇关于如何克隆jQuery Datepicker输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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