克隆datepicker对象[JQuery] [英] Cloning datepicker objects [JQuery]

查看:120
本文介绍了克隆datepicker对象[JQuery]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段,我通过css类将其定义为日期选择器.现在,我想克隆此输入字段并具有它,因此克隆的输入也是日期选择器.

I have an input field that I define as a datepicker through a css class. I now want to clone this input field and have it so the cloned inputs are also datepickers.

从各种来源阅读后,我被引导相信以下代码应该起作用,但事实并非如此.我希望也许有人可以帮助我弄清楚我做错了什么:)

After reading from various sources I was lead to believe that the following code should work but it doesn't. I was hoping maybe someone could help me figure out what I was doing wrong :)

<input type="text" id="date" name="date" class="calendar" />
<input type="button" id="clone" name="clone" value="Clone dates" />

这是javascript:

And here's the javascript:

<script type="text/javascript">
$(document).ready(function(){

 $('.calendar').datepicker();

 $('#clone').click(function()
 {
  $('.calendar:last').clone().append().insertAfter('.calendar:last');
 });

});

</script>

到目前为止,输入字段是重复的,并插入到最后一个实例之后,但是datepicker不起作用.我尝试将'true'传递给克隆函数,但它给我一个错误,提示未定义 inst .

So far the input field is duplicated and is inserted at after the last instance but the datepicker doesn't work. I tried passing 'true' to the clone function but it gave me an error saying that inst wasn't defined.

任何帮助将不胜感激:)

Any help would be appreciated :)

推荐答案

将其更改为此:

$('.calendar:last').clone(false).removeClass('hasDatepicker').insertAfter('.calendar:last').datepicker();

这篇关于克隆datepicker对象[JQuery]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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