我有两个输入字段,Id 和 Desc。我需要一个 javascript,它根据已经设置的一些字段在第二个文本字段中输入值。就像圣诞节一样,如果输入 12/25,它应该说圣诞节。
它为一个价值工作。但是,如果我输入“else if”,则它不适用于多个值。
<script type="text/javascript">
$(document).ready(function() {
$('#holidayDate').datepicker();
var availableTags = ["New years Day", "Martin Luther King Day", "Groundhog Day", "Valentine's Day", "Washington's Birthday", "Easter", "Earth Day", "National Arbor Day", "Mother's Day", "Memorial Day", "Flag Day", "Father's Day", "Independence Day", "Labor Day", "Columbus Day", "Halloween", "Veterans Day", "Thanksgiving Day", "Pearl Harbor Remembrance Day", "Christmas Day"];
$("#tags").autocomplete({source:availableTags});
$('#holidayDate').change(function() {
if ($(this).val().substring(0, 5) === '12/25') {
$('#tags').val('Christmas Day');
}else if ($(this).val().substring(0, 5) === '01/01') {
$('#tags').val('New years Day');
} else {
$('#tags').val('');
}
});
});
</script>