我有3个选项的下拉菜单(关键,主要,次要)。现在,如果我选择关键,那么日期应该是今天的日期+ 3,例如今天是16-05-2019,所以如果我选择关键的日期在datepicker输入中显示的应该是19-05-2019,如果我选择“ major”,则日期选择器应该显示(今天的日期+ 7),因此它将显示23-05-2019
$(document).ready(function() {
$("#date-in").datepicker().datepicker("setDate", new Date());
$('#priority').on('change', function() {
changeDate();
});
});
function changeDate() {
var date = $('#date-in').datepicker("getDate");
var pvalue = $('#priority').val();
if (pvalue === 'Critical')
pvalue = 3;
if (pvalue === 'Major')
pvalue = 7;
if (pvalue === 'Minor')
pvalue = 30;
date.setDate(date.getDate() + parseInt(pvalue));
$("#date-in").datepicker("setDate", date);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<select class="form_line_only form-control" name="ho_night" id="priority">
<option selected> none </option>
<option> Critical </option>
<option> Major </option>
<option> Minor </option>
</select>
<input type="text" class="date_c" id="date-in">
所以我可以增加日期,但它会增加显示的当前值