为什么选择JS创建的选项有限或未显示?

时间:2016-07-10 20:16:11

标签: javascript

一个非常有趣的事情是我的代码。我有3个不同的选择,一个是多年,第二个是几个月,第三个是几天。我通过JS创建了多年和几天的选项。我的问题是我的年份列表从起点开始,但不会在我给出的结束点结束,但是当我将j的起点改为300时,一切都很完美。原因是什么,或者是我的代码不正确? https://jsfiddle.net/arminemash/f9gy1p4L/15/

 select{float:left}
  #month,#days,input{display:none} 

 <body onload='addOptions()'>
    <form action=''>
      <select required id='year' class='selectOption' onchange='select(this)'>
         <option value=""> Select year</option> 

      </select>
       <select required id='month' class='selectOption' onchange='select(this)'>
        <option value=""> Select month</option>
        <option value="January">January</option>
        <option value="February">February</option>
        <option value="March">March</option>
        <option value="April">April</option>
        <option value="May">May</option>
        <option value="June">June</option>
        <option value="July">July</option>
        <option value="August">August</option>
        <option value="September">September</option>
        <option value="October">October</option>
        <option value="November">November</option>
        <option value="December">December</option>
      </select>

    <select required id='days' class='selectOption' onchange='select(this)'>
      <option value="">Select Day</option>
    </select>

    <input type="submit" class='selectOption' onclick='getDate()'> 

  </form>
</body>


function addOptions(){    
   var x= document.getElementById('year');  
   var y = document.getElementById('days'); 
   for(var i=1900,j=1;i<3000,j<=31;i++,j++){
     var option1 = document.createElement("option");
     var option2 = document.createElement("option");
     option1.text =i;
     x.add(option1);
     option2.text =j;
     y.add(option2);
   }
}

 var i=0;           
 function select(par){
    var x=document.getElementsByClassName('selectOption');
    if( par.selectedIndex !== "0"){ 
      x[i+1].style.display='block';             
      i++;
      collectData.push(par.value);
    }       
   }

1 个答案:

答案 0 :(得分:0)

问题是你的循环。 using (var db = new DB()) { var result = db.users .Where(u => u.username == txtUsername.Text && u.password == txtPassword.Text) .Select( a => new User { id = a.user_id, name = a.username, roleID = a.role_id }) .ToList(); //error here } 当j达到31时,这将停止。你需要的是两个for循环,一个是天,一个是多年。我编辑了你的小提琴here.