【问题标题】:how to Add the days using Dropdown list?如何使用下拉列表添加天数?
【发布时间】:2016-03-19 13:48:54
【问题描述】:

大家好,希望你们没事:) 需要帮助或从选择下拉列表中更改日期 这是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");
        }

提前致谢

【问题讨论】:

  • alert document.getElementById("TextBoxStartDate"); 它给了你什么?

标签: javascript c# jquery asp.net


【解决方案1】:

我首先想到的是 Combobox。如果我明白你的意思,我会这样做。

    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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-27
    • 2020-01-07
    • 2021-01-03
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    相关资源
    最近更新 更多