【问题标题】:Bootstrap datepicker is not showing calender after cloning in jquery在 jquery 中克隆后,Bootstrap datepicker 不显示日历
【发布时间】:2014-12-24 10:52:14
【问题描述】:

我正在使用 grails 2.1.1 和 jquery。我有一个表格,其中每行有三个字段,例如审核员、指定和审核日期。所以我声明了一个函数,它将克隆表的最后一行并将其添加为最后一行。现在它正在这样做,但问题是选择框和文本字段可以用于克隆,但日期选择器除外。它也克隆了日期选择器,但是当我单击它时,它不会显示要选择的日历,但在第一行会显示。我已经搜索了护目镜并尝试了很多东西但没有结果。谁能帮我解决这个问题?!!!下面是我的代码::

我的表格和操作按钮 >>>

<table id="auditors" class="auditors">
        <tr><th>Auditor Name</th><th>Designation</th><th>Audit Date</th></tr>
        <tr>
            <td><g:select id="auditor0" name="auditor0" from="${audit.Auditor.list()}" optionKey="id" optionValue="AUDITOR_NAME" noSelection="['':'নির্বাচন করুন']" required="" value="${upManagementLetterInstance?.upRepresentative?.auditor?.id}" class="form-control"/></td>
            <td><g:textField name="auditorDesignation0" id="auditorDesignation0" readonly="" class="form-control"/> </td>
            <td><div class="bfh-datepicker" id="auditDate0" data-date="${formatDate(format:'MM/dd/yyyy',date:upManagementLetterInstance?.upRepresentative?.auditDate)}" data-close="true" data-name="auditDate0"></div></td>                
        </tr>
    </table>

    <input type="button"  value="Add Another Auditor" onclick="addAnotherAuditor()"/>

我的功能>>>

    <script>
var initialCounter = 0,addedCounter = 1;
function addAnotherAuditor(){
        var row = $(".auditors > tbody > tr:last").clone();
        row.find('select').each(function(){
            this.id= this.name.replace(initialCounter, addedCounter);
            this.name= this.name.replace(initialCounter, addedCounter);
        })
        $(".auditors > tbody > tr:last").after(rows);

        initialCounter++;
        addedCounter++;
    }
</script>

【问题讨论】:

  • 您能否提供有关您正在使用的引导日期选择器的信息?有很多,因此很难解释如何将它绑定到新添加的元素。
  • @JoshuaMoore 感谢您的回复,我正在使用 Bootstrap v3.2.0
  • 你在使用这个日期选择器组件/库吗?:bootstrapformhelpers.com/datepicker
  • 这里是 js 信息 >> eyecon.ro/bootstrap-datepicker & 这里是 css 信息 >> 版权所有 2012 Stefan Petre * 在 Apache License v2.0 下获得许可 * apache.org/licenses/LICENSE-2.0

标签: jquery twitter-bootstrap grails


【解决方案1】:

我在代码中看不到任何地方,您可以在其中初始化已克隆的新日期选择器。虽然将复制 DOM 和相关样式,但已附加到原始日期选择器的任何事件处理程序都不会转移到新的事件处理程序中。您可以执行以下两项操作之一:

  1. 使用 .clone(true) 告诉 JQuery 引入所有关联的事件处理程序(这可能会产生一些不受欢迎的副作用)
  2. 每次进行克隆时,都将克隆初始化为日期选择器,就像第一个一样。

在我看来,2 是更好的选择。

【讨论】:

  • 如何将克隆初始化为日期选择器?任何想法
  • 使用适当的 jquery 选择器并在其上调用 .datepicker() 。在你的情况下:$('.bfh-datepicker').datepicker()
猜你喜欢
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-05
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
相关资源
最近更新 更多