大家好希望你们都好:) 我需要帮助我想通过从下拉列表中选择天数、周数和月数来更改日期,并从文本框中输入天数、周数和月数,如果我输入数字天数但不工作,这里所有代码都可以正常工作或从选择下拉列表中更改日期 这是javascript
<script>
function addDate() {
debugger;
//Get the entered datevalue
var enteredDateVal = new moment(document.getElementById("TextBoxStartDate").value);
//Get the days to add
var numberofDays = document.getElementById("TextBoxpredictDays").value
//Add the days using add method in moment.js
enteredDateVal.add("Days", parseInt(numberofDays));
//Assign the value in textbox
document.getElementById("TextBoxPredictedClosing").value = enteredDateVal.format("DD-MM-YYYY");
}
</script>
这是我的按钮点击代码,但我想在下拉菜单中如何做到这一点,我不知道:(
protected void Button1_Click(object sender, EventArgs e)
{
DateTime dtval = DateTime.Parse(TextBoxStartDate.Text);
//Add values here
DateTime formatteddays = dtval.AddDays(Int16.Parse(TextBoxpredictDays.Text));
TextBoxPredictedClosing.Text = formatteddays.ToString("DD-MM-YYYY");
}
提前致谢
最佳答案
我首先想到的是组合框。如果我明白你的意思,我就会这样做。
public partial class Form1 : Form
{
public static ComboBox DropDown;
public Form1()
{
InitializeComponent();
string[] listMonth = { "01", "02", "03", "04" };
DropDown = new ComboBox();
DropDown.Parent = this;
DropDown.Location = new System.Drawing.Point(50, 50);
DropDown.Items.AddRange(listMonth);
}
private void button1_Click(object sender, EventArgs e)
{
string dropDownText = DropDown.Text;
}
}
关于javascript - 如何使用下拉列表添加日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34260966/