我想在下拉列表中添加customdate,点击它后,应该在MVC中打开日期。
JQuery的
$("#CustomDate").datepicker({
numberOfMonths: 1,
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
});
查看
@Html.DropDownListFor(m => m.Period, new List<SelectListItem>
{
,
new SelectListItem {Value = "03/05/2018", Text = "Current Year" },
new SelectListItem {Value = "03/05/2017", Text = "Last Year" },
new SelectListItem {Value = "CustomDate", Text = "Custom Date"} // want to make CustomDate as link and want to open Date
},
new { @class = "form-control" })
答案 0 :(得分:0)
您可以在下拉列表中添加不同的类,附加jquery更改事件处理程序,然后在其中查找具有“CustomDate”值的元素。满足该条件时,您可以打开日期选择器。请参阅下面的工作示例:
$('.my-select').change(function(evt){
if(this.value === 'Custom'){
console.log('Custom Selected!');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="my-select form-control">
<option value="1">Opt 1</option>
<option value="2">Opt 2</option>
<option value="Custom">Custom Date</option>
</select>