我正在使用它来添加我的用户可以实时编辑的表格。效果很好!我有一个需要能够编辑的日期字段。我想用其中一个字段添加 jquery“ datepicker ”函数。
这是我的 javascript
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#date_"+ID).hide();
$("#starttime_"+ID).hide();
$("#endtime_"+ID).hide();
$("#date_input_"+ID).show();
$("#starttime_input_"+ID).show();
$("#endtime_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var date=$("#date_input_"+ID).val();
var start=$("#starttime_input_"+ID).val();
var end=$("#endtime_input_"+ID).val();
var dataString = 'id='+ ID +'&date='+ date +'&starttime='+start+'&endtime='+end;
$("#date_"+ID).html('<img src="load.gif" />');
if(date.length && starttime.length && endtime.length>0)
{
$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$("#date_"+ID).html(date);
$("#starttime_"+ID).html(starttime);
$("#endtime_"+ID).html(endtime);
}
});
}
else
{
alert('Enter something.');
}
});
$(".editbox").mouseup(function()
{
return false
});
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
});
});
///////CALLING DATEPICKER FUNCTION///////
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
和日期字段
<td width="10%" class="edit_td">
<span id="date_<?php echo $id; ?>" class="text"><?php echo date("m/d/y",strtotime($date)); ?></span>
<input type="text" value="<?php echo $date; ?>" class="editbox" id="date_input_<?php echo $id;?>" />
</td>
我尝试像这样“date_input_ datepicker”将日期选择器添加到 id 中,但它只是中断并且什么都不做。有什么帮助吗?