<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication3.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
<!--
function o(){
arr = document.Form1.TxtJoinDate.value.split("-");
old = new Date(arr[0],parseInt(arr[1],10)-1,arr[2]);
function RemoveAll(oElem) 
{             //清除DropDownList2的所有项
      var i = 0; 
      for (i = oElem.length; i >= 0; i--){ 
      oElem.options.remove(i); 
      } 
      } 
      RemoveAll(document.Form1.ddlLeaveDate) 

for(i=6;i<=6*8;i+=6)
{
old.setMonth(old.getMonth()+6);
m = String(old.getMonth()+1).length == 1 ? "0" + String(old.getMonth()+1) : old.getMonth()+1;
d = String(old.getDate()).length == 1 ? "0" + String(old.getDate()) : old.getDate();
date = old.getFullYear() + "-" + m + "-" + d;
document.Form1.ddlLeaveDate.options.add( new Option(date,date) );
}
}
//-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 104px" type="text" name="TxtJoinDate"
id="TxtJoinDate" runat="server" onchange="o()">
<SELECT style="Z-INDEX: 102; LEFT: 144px; WIDTH: 152px; POSITION: absolute; TOP: 152px"
name="ddlLeaveDate" id="ddlLeaveDate" runat="server">
<OPTION selected></OPTION>
</SELECT><INPUT style="Z-INDEX: 103; LEFT: 152px; POSITION: absolute; TOP: 192px" type="button"
onclick="o()" value="Button" runat="server">
</form>
</body>
</HTML>
<INPUT style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 104px" type="text" name="TxtJoinDate"
id="TxtJoinDate" runat="server" onchange="o()">
这句话中的onchange事件没有用啊  该怎么解决  我要求TxtJoinDate内容改变后就发生

解决方案 »

  1.   

    测试正常呀~~
    function test(){

    arr = document.getElementById("TxtJoinDate").value.split("-");
    old = new Date(arr[0],parseInt(arr[1],10)-1,arr[2]);
    function RemoveAll(oElem) 
    {             //清除DropDownList2的所有项
          var i = 0; 
          for (i = oElem.length; i >= 0; i--){ 
          oElem.options.remove(i); 
          } 
          } 
          RemoveAll(document.getElementById("ddlLeaveDate")) 

    for(i=6;i<=6*8;i+=6)
    {
    old.setMonth(old.getMonth()+6);
    m = String(old.getMonth()+1).length == 1 ? "0" + String(old.getMonth()+1) : old.getMonth()+1;
    d = String(old.getDate()).length == 1 ? "0" + String(old.getDate()) : old.getDate();
    date = old.getFullYear() + "-" + m + "-" + d;
    document.getElementById("ddlLeaveDate").options.add( new Option(date,date) );
    }
    }
      

  2.   

    正解
    <script language="javascript">
    <!--
    function o(){
    arr = document.Form1.TxtJoinDate.value.split("-");
    old = new Date(arr[0],parseInt(arr[1],10)-1,arr[2]);
    function RemoveAll(oElem) 
    {             //清除DropDownList2的所有项
          var i = 0; 
          for (i = oElem.length; i >= 0; i--){ 
          oElem.options.remove(i); 
          } 
          } 
          RemoveAll(document.Form1.ddlLeaveDate) for(i=6;i<=6*8;i+=6)
    {
    old.setMonth(old.getMonth()+6);
    m = String(old.getMonth()+1).length == 1 ? "0" + String(old.getMonth()+1) : old.getMonth()+1;
    d = String(old.getDate()).length == 1 ? "0" + String(old.getDate()) : old.getDate();
    date = old.getFullYear() + "-" + m + "-" + d;
    document.Form1.ddlLeaveDate.options.add( new Option(date,date) );
    }
    }
    //-->
    </script>