我决定使用JQuery UI Datepicker脚本来挑选日期。下面是我的代码的一部分,以及我将其集成到我的PHP页面的方式:
<link type="text/css" href="css/south-street/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript">
$(function(){
// Datepicker
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
//hover states on the static widgets
$('#dialog_link, ul#icons li').hover(
function() { $(this).addClass('ui-state-hover'); },
function() { $(this).removeClass('ui-state-hover'); }
);
});
</script>
和
// date picker (embeds JQuery script)
echo '<label for="datepicker">Date: </label>';
echo '<input type="text" name="datepicker" id="datepicker" />';
echo '<div id="datepicker"></div>';
几乎根据JQuery UI说明。
现在我的问题是:如何在文本输入字段中禁用手动输入?我只希望JQuery Datepicker脚本能够填充文本字段。据我所知,脚本当前阻止用户在文本字段中输入任何非数字字符,但允许任何数字组合(因此,允许使用像“95460829468”这样的乱码)。
答案 0 :(得分:238)
进行输入时,请将其设置为只读。
<input type="text" name="datepicker" id="datepicker" readonly="readonly" />
答案 1 :(得分:24)
我认为你应该补充一下 的风格= “背景:白色;”强> 使它看起来像是可写的
<input type="text" size="23" name="dateMonthly" id="dateMonthly" readonly="readonly" style="background:white;"/>