Web端 年月日下拉表 密码判断 按钮判断是否提交

生日:
<asp:DropDownList ID="selYear" runat="server"></asp:DropDownList>年
<asp:DropDownList ID="selMonth" runat="server"></asp:DropDownList>月
<asp:DropDownList ID="selDay" runat="server"></asp:DropDownList>日

 

 

后台代码

    for (int i = Convert.ToInt32(DateTime.Now.Year); i > 1900; i--)
          {
              ListItem li = new ListItem();
              li.Text = i.ToString();
              li.Value = i.ToString();
              selYear.Items.Add(li);
          }
          for (int i = 1; i < 13;i++ )
          {
              ListItem li = new ListItem();
              li.Text = i.ToString();
              li.Value = i.ToString();
              selMonth.Items.Add(li);
          }
          for (int i = 1; i < 32;i++ )
          {
              ListItem li = new ListItem();
              li.Text = i.ToString();
              li.Value = i.ToString();
              selDay.Items.Add(li);
          }
View Code

js代码

  var Year = window.document.getElementById("selYear");
    var Month = window.document.getElementById("selMonth");
    var Day = window.document.getElementById("selDay");
    Year.onchange = function () {
        
        dropchang();
    }
    Month.onchange = function () {
        
        dropchang();
    }
    function dropchang()
    {
        if (Month.value == "4" || Month.value == "6" || Month.value == "9" || Month.value == "11")
        { days(30); }
        else if (Month.value == "2")
        {
            if ((Year.value % 4 == 0 && Year.value % 100 != 0) || Year % 400 == 0)
            { days(29); }
            else
            { days(28);}
        }
    }

    function days( count )
    {
        Day.options.length = 0;
        for(var i=1;i<=count;i++)
        {
            Day.value.length=0;
            var op=document.createElement("option");
            op.value=i;
            op.innerHTML=i;
            Day.appendChild(op);
        }
    }
View Code

 

 

密码判断

密码:
<asp:TextBox ID="TextBox2" TextMode="Password" runat="server"></asp:TextBox><br />
确认密码:
<asp:TextBox ID="TextBox3" TextMode="Password" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>

 

js代码

 // 判断密码是否一致    给按钮用的是否提交
    var ispwd = false;
    var txt2 = document.getElementById("TextBox2");
    var txt3 = document.getElementById("TextBox3");
    var label2 = document.getElementById("Label2");


    function Pwd (p1,p2)
    {
        if(p1.value==p2.value)
        {
            label2.innerText="正确";
            label2.style.color="green";
            ispwd=true;
        }
        else
        {
            label2.innerText="密码不一致";
            label2.style.color = "red";
           
            ispwd=false;
        }
    }
    txt2.onkeyup = function () { Pwd(txt2, txt3); }
    txt3.onkeyup = function () { Pwd(txt2, txt3); }
View Code

 

 

按钮提交

 <asp:Button ID="Button1" OnClientClick="return go();" runat="server" Text="Button" />

js代码    用密码是否一致 和昵称  不能为空  判断是否正确  正确才能提交

function go()
{
return ispwd && nickname;
}

 

posted @ 2017-05-22 16:31  天晴微笑  阅读(158)  评论(0编辑  收藏  举报