无法使用onchange获取当天的输出

时间:2016-09-11 18:11:58

标签: html

  

我根据自己的想法来实现如何获得2月份的闰年,以及输出日期范围的月份和年份的条件。

这是我的HTML代码......

<tr>
    <td align="right">Expect to Loan:</td>
    <td colspan="1">
    <select name="month" onchange="getday();">
    <option value="0">Month</option>
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>            
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>

</select>

<select name="day" id="day" style="margin-left:5px;">
<option value="">Day</option>


</select>


<select name="year" id="year" style="margin-left:5px;">
<option value="0">Year</option>

<script type="text/javascript">

var date = new Date();
var yr = date.getFullYear('yyyy');

for (var i = 1; i <= 10; i++) {

document.write("<option value='" + yr + "'>" + yr + "    </option>");
            yr = yr + 1;
            }

        </script>


    </select>


    </td>
</tr>

我的Javascript代码表示每月和每年的每次更改

    <script type="text/javascript">

        function getday(){
        var month = document.forms['calcu']['month'].value;

        alert('month change');

        if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){

        for (var = 1; i <= 31; i++) {

            alert('date end on 31');
            document.write("<option value='" + i + "'>" + i + "</option>");

            }
    }

    else if(month == 4 || month == 6 || month = 9 || month == 9 || month == 11){
        for (var = 1; i <= 30; i++) {

            alert('date end on 30');

            document.write("<option value='" + i + "'>" + i + "</option>");

            }
    }

        </script>
  

我应该使用什么DOM事件来获取日期输出。   请帮我处理我的密码。

&#13;
&#13;
<script type="text/javascript">
				
				var date = new Date();
				var yr = date.getFullYear('yyyy');

			for (var i = 1; i <= 10; i++) {

				document.write("<option value='" + yr + "'>" + yr + "</option>");
				yr = yr + 1;
				}

	</script>
            

	<script type="text/javascript">

			function getday(){
			var month = document.forms['calcu']['month'].value;
			
			//alert('month change');

			if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){

			for (var = 1; i <= 31; i++) {

			//	alert('date end on 31');
				document.write("<option value='" + i + "'>" + i + "</option>");

				}
		}

		else if(month == 4 || month == 6 || month == 9 || month == 9 || month == 11){
			for (var = 1; i <= 30; i++) {

				//alert('date end on 30');

				document.write("<option value='" + i + "'>" + i + "</option>");

				}
		}

			</script>
&#13;
<select name="month" onchange="getday();">
		<option value="0">Month</option>
		<option value="1">January</option>
		<option value="2">February</option>
		<option value="3">March</option>
		<option value="4">April</option>			
		<option value="5">May</option>
		<option value="6">June</option>
		<option value="7">July</option>
		<option value="8">August</option>
		<option value="9">September</option>
		<option value="10">October</option>
		<option value="11">November</option>
		<option value="12">December</option>

		</select>

		<select name="day" id="day" style="margin-left:5px;">
			
			<option value="">Day</option>


		</select>


		<select name="year" id="year" style="margin-left:5px;">
			
			<option value="0">Year</option>
			
		</select>
&#13;
&#13;
&#13;

0 个答案:

没有答案