jquery - 如何多次使用日期选择器?
问题描述
这是我的表格:
<div class="educationalInfo__wrapper">
<div class="row educationalInfo">
<div class="col-md-2">
<form>
<div class="col-md-2">
<div class="form-group">
<label><code>* </code>تاریخ شروع</label>
<input type="text" class="clear startdate" name="education[startdate][]" id="startdate" tabindex="14">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label><code>* </code>تاریخ پایان</label>
<input type="text" class="enddate clear" name="education[enddate][]"" id="enddate" tabindex="14">
</div>
</div>
<div class="col-md-1 col-sm-1 col-xs-2">
<div class="form-group plus-mg">
<label></label>
<a href="javascript:void(0)" id="educationalInfo__add" tabindex="42">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
</div>
</form>
</div>
</div>
</div>
我正在使用克隆来复制表格:
$('#educationalInfo__add').click(function () {
var clone_r = $('.educationalInfo').eq(0).clone(true);
clone_r.find('.clear').val('');
$('.educationalInfo__wrapper').append(clone_r);
$(".gpa").mask("99/99", {placeholder: "../.."});
$(".enddate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
$(".startdate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
});
但是日期选择器只适用于第一个,即使我点击另一个它也只属于第一个。我使用了类,但没有用。有了这个描述,有人可以帮我解决这个问题吗?
解决方案
试试这个代码
$('#educationalInfo__add').click(function() {
var clone_r = $('.educationalInfo').eq(0).clone(false);
clone_r.find('.clear').val('');
$('.educationalInfo__wrapper').append(clone_r);
//$(".gpa").mask("99/99", {placeholder: "../.."});
clone_r.find('.startdate').each(function() {
$(this).removeAttr('id').removeClass('hasDatepicker'); //
$('.startdate').datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
});
clone_r.find('.enddate').each(function() {
$(this).removeAttr('id').removeClass('hasDatepicker'); //
$('.enddate').datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
});
});
$(".enddate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
$(".startdate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-50:-15',
dateFormat: 'yy/mm/dd'
});
推荐阅读
- azure-log-analytics - 巧妙地格式化毫秒
- python - 熊猫替换一列中的值基于另一列
- python - 无法让 Flask、Gunicorn 和 Nginx 工作
- vba - 将excel表格分解为文本文件 - 格式化
- excel - 如何留出时间通过 Excel 中的 VBA 从 Bloomberg 刷新 BDH 公式?
- javascript - 如何将 UL 元素插入列表
- ejs - 如何从Nodejs的上传文件夹上传Ejs中的img
- sql - SQL 查询以获取最新创建的具有属性的所有行
- firebase - 是否应该对所有发布请求进行 CSRF 检查?
- python - 1064, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以获取在 '%s 附近使用的正确语法)