问题
I am adding input field dynamically to a td
element
$('.edit_text').live('click',function(){
$(this).html('<input type="text" value="'+$(this).text()+'" style="background:url(text_bx.gif) no-repeat bottom;display:inline;padding: 0; margin: 0;" class="editing" >');
$(this).children('input').focus();
if ($(this).attr('id')=='date'){
$(this).children('input').datepicker( "refresh");//"option", "dateFormat","yy-mm-dd");
}
});
But if td has id date, datepicker is not showing up. I also have blur function on inserted input field, is that a problem?
$('.editing').live('blur',function(){
//did something
});
回答1:
Well, Below is the dynamic jquery date picker
with editable textbox you can update the code accordingly.
$(function(){
$('#thedate').datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function(dateText) {
$('#dateContainer').text(dateText);
console.log(dateText);
}
});
});
<link href="http://code.jquery.com/ui/1.8.21/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>
Shown Date : <div id="dateContainer" type="button" > currentData </div>
<input id="thedate" type="text" /><br />
<input id="thesubmit" type="button" value="Submit" />
JS Fiddle with date picker:- http://jsfiddle.net/vikash2402/8w8v9/1989/
JS Fiddle with date picker and div:- http://jsfiddle.net/vikash2402/8w8v9/1990/
Hoping this will help you :)
来源:https://stackoverflow.com/questions/11486660/jquery-ui-datepicker-not-working-on-dynamically-inserted-input