gpt4 book ai didi

html - 任何人都有一些用于 asp.net mvc 的下拉列表日期选择器

转载 作者:可可西里 更新时间:2023-11-01 14:58:36 26 4
gpt4 key购买 nike

有人知道我在哪里可以找到 html 帮助程序或将生成由 3 个下拉菜单组成的日期选择器的东西吗?

最佳答案

这是我的小 helper 。

我相信这本身就是解释性的。可以调整以安排下拉菜单的顺序(月/日/年或日/月/年),如果您使用的是 .NET 4,则可以为名称设置默认参数。

编辑:清除文本以减少眼睛流血

/// <summary>
/// Creates a days, months, years drop down list using an HTML select control.
/// The parameters represent the value of the "name" attribute on the select control.
/// </summary>
/// <param name="dayName">"Name" attribute of the day drop down list.</param>
/// <param name="monthName">"Name" attribute of the month drop down list.</param>
/// <param name="yearName">"Name" attribute of the year drop down list.</param>
/// <returns></returns>
public static string DatePickerDropDowns(this HtmlHelper html, string dayName, string monthName, string yearName)
{
TagBuilder daysList = new TagBuilder("select");
TagBuilder monthsList = new TagBuilder("select");
TagBuilder yearsList = new TagBuilder("select");

daysList.Attributes.Add("name", dayName);
monthsList.Attributes.Add("name", monthName);
yearsList.Attributes.Add("name", yearName);

StringBuilder days = new StringBuilder();
StringBuilder months = new StringBuilder();
StringBuilder years = new StringBuilder();

int beginYear = DateTime.UtcNow.Year - 100;
int endYear = DateTime.UtcNow.Year;

for (int i = 1; i <= 31; i++)
days.AppendFormat("<option value='{0}'>{0}</option>", i);

for (int i = 1; i <= 12; i++)
months.AppendFormat("<option value='{0}'>{0}</option>", i);

for (int i = beginYear; i <= endYear; i++)
years.AppendFormat("<option value='{0}'>{0}</option>", i);

daysList.InnerHtml = days.ToString();
monthsList.InnerHtml = months.ToString();
yearsList.InnerHtml = years.ToString();

return string.Concat(daysList.ToString(), monthsList.ToString(), yearsList.ToString());
}

关于html - 任何人都有一些用于 asp.net mvc 的下拉列表日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2462925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com