我有约会和描述。如果输入日期,则说明应自动完成。如果选择12/25 / yyyy,那么圣诞节应该自动显示?
我试过这个,但它不起作用。有什么帮助吗?
<html>
<head>
<script type="text/javascript">
$(function() {
$('#date').datepicker();
});
$(function() {
var availableTags = ["Christmas Day","etc"];
$("#tags").autocomplete({
source: availableTags
});
});
$('#date').change( function() {
if ($(this).val().substring(0, 5) === '12/25') {
$('#tags).val('Christmas');
} else {
$('#tags').val('');
}
});
</script>
<body>
<DIV class="ui-widget">Date: <INPUT TYPE="TEXT" name="xx"
property="xx" id="date" />
</P>
<input type="text" id="tags'" name="tags'" />
</DIV>
</body>
</html>
答案 0 :(得分:0)
这样做,每个特殊日子的每一天都需要在后端有一个庞大的数据库。但它可能不起作用,因为一天有很多特殊日子,或者两天内可能会发生一个特殊日子。
如果您每个日期只有一天,我会将日期(或当天的描述)发送到后端,然后返回可能的建议。如果您没有设置任何日期,我甚至会为描述启用自动完成功能。
在描述的响应中,我会在大括号中显示文本和日期,然后在用户选择选项时立即将日期添加到第一个输入。
答案 1 :(得分:0)
使用onchange
事件。使用jQuery ...
$('#dateInputId').change( function() {
if ($(this).val().substring(0, 5) === '12/25') {
$('#secondInputId').val('Christmas');
} else {
$('#secondInputId').val('');
}
});