2012-07-14 65 views
0

我动态地添加输入字段到td元素jQuery UI的动态插入输入

$('.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具有标识日期,日期选择器没有显示出来。 我也有插入输入字段模糊功能,是一个问题?

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

您可以张贴在的jsfiddle?也尝试使用一些不同的名称,而不是“日期”,这可能会让你陷入困境 – Samson 2012-07-14 19:18:42

+0

代码有点复杂,我添加了console.log(0)if语句后,它的工作 – pahnin 2012-07-14 19:20:25

回答

0

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

$(function(){ 
 
    
 
    $('#thedate').datepicker({ 
 
     dateFormat: 'dd-mm-yy', 
 
     onSelect: function(dateText) { 
 
    \t \t $('#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拨弄日期选取器: - http://jsfiddle.net/vikash2402/8w8v9/1989/

JS拨弄日期选取器和DIV: - http://jsfiddle.net/vikash2402/8w8v9/1990/

希望这将帮助你:)