![screenshot](https://oss-cn-
hangzhou.aliyuncs.com/yqfiles/6a9ba2ffb64c1d6d7cd878102bbfb6ec39ea59d6.png)
如上图所示,当用户点击按钮时,添加一行新的表单,然而添加的表单无法选择日期。我试了一下如果直接手工复制同样的表单在页面中,可以正常填写的。难道js加载完成后再向页面添加的元素就无法加载js特效了么?求解!!!!
js代码如下:
<script type="text/javascript">
$(document).ready(function(){
$("#add_relation").click(function(){
$("#relation").append('<div class="col-md-2"><div class="form-group"><input name="family_relation"placeholder="与本人关系"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="family_name"placeholder="姓名"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="family_age"placeholder="年龄"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="family_employer"placeholder="工作单位"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="family_position"placeholder="职位"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="family_contact"placeholder="联系方式"class="form-control"></div></div>');
obj = document.getElementsByName("family_relation");
if (obj.length >= 3) {
$("#add_relation").remove('#add_relation');
}
});
$("#add_experience").click(function(){
$("#experience").append('<div class="col-md-2"><div class="input-group date-picker input-daterange"data-date-format="yyyy-mm-dd"><input name="old_employed_time"type="text" class="form-control" placeholder="入职时间"><span class="input-group-addon">to</span><input name="old_departure_time"type="text" class="form-control" placeholder="离职时间"></div></div><div class="col-md-2"><div class="form-group"><input name="old_company_name"placeholder="公司名称"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="old_company_position"placeholder="职位"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="old_company_salary"placeholder="薪资"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="old_company_references"placeholder="证明人"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="old_company_contact"placeholder="联系电话"class="form-control"></div></div>');
obj = document.getElementsByName("old_employed_time");
if (obj.length >= 3) {
$("#add_experience").remove('#add_experience');
}
});
$("#add_education").click(function(){
$("#education").append('<div id="education"class="row"><div class="col-md-2"><div class="form-group"><input name="education_enrollment_date"data-date-format="yyyy-mm-dd"placeholder="入学时间"class="form-control form-control-inline date-picker"/></div></div><div class="col-md-2"><div class="form-group"><input name="education_graduation_date"data-date-format="yyyy-mm-dd"placeholder="毕业时间"class="form-control form-control-inline date-picker"/></div></div><div class="col-md-2"><div class="form-group"><input name="education_school_name"placeholder="所在院校"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="education_specialty"placeholder="所学专业"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="education_diploma"placeholder="学历"class="form-control"></div></div><div class="col-md-2"><div class="form-group"><input name="education_degree"placeholder="所获学位"class="form-control"></div></div></div>');
obj = document.getElementsByName("education_enrollment_date");
if (obj.length >= 3) {
$("#add_education").remove('#add_education');
}
});
});
</script>
$("#add_experience").click(function(){
$("#experience").append('添加的html代码');
$('.input-daterange').datepicker({});//选取新增表单的class,然后绑定
obj = document.getElementsByName("old_employed_time");
if (obj.length >= 3) {
$("#add_experience").remove('#add_experience');
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。