admin管理员组文章数量:1026989
I have successfully attached jquery UI datePicker to a dynamically created textbox, Al works fine excepts when I select a date it is not ing in corresponding textbox, But it es in my first textbox which is not dynamically created. My code is like this
$(".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 Here
I have successfully attached jquery UI datePicker to a dynamically created textbox, Al works fine excepts when I select a date it is not ing in corresponding textbox, But it es in my first textbox which is not dynamically created. My code is like this
$(".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 Here
Share Improve this question asked Mar 15, 2014 at 10:48 NoneNone 5,68023 gold badges93 silver badges178 bronze badges 2- Try jsfiddle/xUYM2 ( i just use more accurate indication of elements to create datepicker ) – Vasiliy vvscode Vanchuk Commented Mar 15, 2014 at 11:33
- Ahhh..That work like a charm. You can add this as answer here :) – None Commented Mar 15, 2014 at 11:38
2 Answers
Reset to default 5Try to use more accurate indication of elements to create datepicker. Like here http://jsfiddle/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> it will be better to use local variables in you script like
var $this = $(this); // without var keyword your variable will be global
var $section = $($("." + $this.attr("data-section"))[0]).html();
Add this line in the add-more function
$(".datepicker").removeClass('hasDatepicker').datepicker();
I have successfully attached jquery UI datePicker to a dynamically created textbox, Al works fine excepts when I select a date it is not ing in corresponding textbox, But it es in my first textbox which is not dynamically created. My code is like this
$(".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 Here
I have successfully attached jquery UI datePicker to a dynamically created textbox, Al works fine excepts when I select a date it is not ing in corresponding textbox, But it es in my first textbox which is not dynamically created. My code is like this
$(".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 Here
Share Improve this question asked Mar 15, 2014 at 10:48 NoneNone 5,68023 gold badges93 silver badges178 bronze badges 2- Try jsfiddle/xUYM2 ( i just use more accurate indication of elements to create datepicker ) – Vasiliy vvscode Vanchuk Commented Mar 15, 2014 at 11:33
- Ahhh..That work like a charm. You can add this as answer here :) – None Commented Mar 15, 2014 at 11:38
2 Answers
Reset to default 5Try to use more accurate indication of elements to create datepicker. Like here http://jsfiddle/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> it will be better to use local variables in you script like
var $this = $(this); // without var keyword your variable will be global
var $section = $($("." + $this.attr("data-section"))[0]).html();
Add this line in the add-more function
$(".datepicker").removeClass('hasDatepicker').datepicker();
本文标签: javascriptjquery ui datepicker not working with dynamic htmlStack Overflow
版权声明:本文标题:javascript - jquery ui datepicker not working with dynamic html - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745663055a2162007.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论