jquery - 如何在下拉列表中添加“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" })
解决方案
您可以将不同的类添加到下拉列表中,附加一个 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>
推荐阅读
- python - 使用 python 从 youtube 上抓取视频信息
- json - 如何使用 jq 提取 json 值子字符串
- ssl - 使用 Cloudflare 的共享 SSL 时,应如何在 Google 的 API 下列出 HTTP?
- javascript - 如何更新数组中所有对象的键
- mysql - 如何使用现有表中的列创建新表?
- jenkins-pipeline - Jenkins 中的 Terraform 远程状态
- java - 将单词转换为字符整数表示的总和
- c++ - std::copy 行为和指针算法
- javascript - 刽子手游戏只匹配第一个字符,而不是所有字符
- c# - 我如何为 DryIOC 中的开放泛型“注册委托”?