Jquery UI datepicker不能与动态html一起工作
jquery ui datepicker not working with dynamic html
我已经成功地将jquery UI datePicker连接到一个动态创建的文本框,除了当我选择一个日期时,它不会出现在相应的文本框中,但它出现在我的第一个文本框中,这不是动态创建的。我的代码是这样的
$(".add-more").click(function () {
$this = $(this);
$section = $($("." + $this.attr("data-section"))[0]).html();// This is a section in my HTML with multiple textboxes
$this.parent().append('<div class=' + $this.attr("data-section") + '>' + $section + '</div>').fadeIn();
$(".datepicker").removeClass('hasDatepicker').datepicker();
});
HTML <div id="Div1" class="section-container">
<div class="education-item" style="display: none">
<p>Institute:<input type="text" name="txtInstitute" /></p>
<p>Start Year:<input type="text" name="txtStartYear" class="datepicker" /></p>
<p>End Year:<input type="text" name="txtEndYear" class="datepicker"/></p>
</div>
</div>
这里的JSFiddle
尝试使用更准确的元素指示来创建日期选择器。比如这里http://jsfiddle.net/xUYM2/
$(".add-more").click(function() {
$this = $(this);
$section = $($("." + $this.attr("data-section"))[0]).html();
var block = $('<div class=' + $this.attr("data-section") + '>' + $section + '</div>')
$this.parent().append(block).fadeIn();
block.find(".datepicker").removeClass('hasDatepicker').datepicker();
showHideRemove($(this).parents(".section-container").find(".remove-item"), 1);
});
p。S>,最好在脚本中使用局部变量,如
var $this = $(this); // without var keyword your variable will be global
var $section = $($("." + $this.attr("data-section"))[0]).html();
在Add -more函数中添加这一行
$(".datepicker").removeClass('hasDatepicker').datepicker();
相关文章:
- 如何将具有相同功能的两个select html标签的两个JS组合在一起
- 将HTML文件中的变量与外部JS文件一起使用
- 我的HTML、CSS和Javascript应该放在一起还是分开
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- 加载 HTML 模板以通过浏览器与挖空组件一起使用
- 如何将html中select选项的输入与javascript一起使用
- HTML/Javascript/CSS框堆叠在一起
- 如何将动态html与注入角度引导popover的指令一起使用
- 将 Jquery 与 html 一起使用
- 如何在使用 Flask 后端时将图像和资产与 HTML 一起使用
- 将Dart与HTML一起使用(我可以在Javascript中做的事情)
- 将 Jquery 与 php 和 html 一起使用
- Django-将JSON数据和HTML一起传递到前端不起作用
- 当与.html一起使用时,.hooper不起作用
- 如何使javascript与使用ajax加载的html一起工作
- 上下文菜单不能与Javascript生成的HTML一起工作
- 在添加类的情况下,CSS 3的过渡是否不能与模板元素(HTML 5)一起工作?
- Ng-click不能与ng-bind-html一起使用
- Angularjs - form ng-submit不能与动态生成的form html一起工作
- Jquery UI datepicker不能与动态html一起工作