0

我正在将输入字段动态添加到td元素

$('.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");
    }
});

但如果 td 有 id 日期,则 datepicker 不会出现。我在插入的输入字段上也有模糊功能,有问题吗?

$('.editing').live('blur',function(){
//did something
    });
4

1 回答 1

0

好吧,下面是jquery date picker带有可编辑文本框的动态,您可以相应地更新代码。

$(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:- http://jsfiddle.net/vikash2402/8w8v9/1989/

带有日期选择器和 div 的 JS Fiddle:- http://jsfiddle.net/vikash2402/8w8v9/1990/

希望这会帮助你:)

于 2016-10-05T19:43:28.123 回答