老坛衫菜463 2022-10-20 15:15 采纳率: 62.5%
浏览 30
已结题

请问为什么我输不出来是否是闰年

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            margin: auto;
            border: 1px solid black;
            border-collapse: collapse;
        }
        
        tr,
        td {
            height: 40px;
            color: blue;
            text-align: center;
            border: 1px solid black;
        }
    </style>

    <body>

        <h1 align='center'>判断出生年份是否为闰年</h1>
        <table>
            <tr>
                <td>学院:</td>
                <td>软件学院</td>
            </tr>
            <tr>
                <td>姓名:</td>
                <td>黄楚</td>
            </tr>
            <tr>
                <td>学号:</td>
                <td>211451082208</td>
            </tr>
            <tr>
                <td>出生年份:</td>
                <td><select name="year" id="year" onchange='f()'>
                    <option value="1998">1998年</option>
                    <option value="1999">1999年</option>
                    <option value="2000">2000年</option>
                    <option value="2001">2001年</option>
                    <option value="2002">2002年</option>
                    <option value="2003">2003年</option>
                    <option value="2004">2004年</option>
                </select>
                </td>
            </tr>
            <tr>
                <td>出生年份是否为闰年:</td>
                <td id='answer'></td>
            </tr>
        </table>
        <script>
            function isRunYear(year){
                 if(year%4==0&&year%100!=0){
                     return true;
                 }else{
                     return false;
                 }
            }
            function f(){
                var y=document.getElementsById('year');
                var i=y.selectedIndex;
                var s=isRunYear(y[i].value);
                if(s==true){
                    document.getElementById('answer').value=y[i].value+"是闰年";
                }else{
                    document.getElementById('answer').value=y[i].value+"不是闰年";
                }
            }
        </script>
    </body>

</html>

  • 写回答

1条回答 默认 最新

  • 面向百度编程cv 2022-10-20 15:30
    关注
    
     function f() {
                var y = document.getElementById('year'); //重点
                var i = y.selectedIndex;
                var s = isRunYear(y[i].value);
                if (s == true) {
                    document.getElementById('answer').innerText = y[i].value + "是闰年";
                } else {
                    document.getElementById('answer').innerText = y[i].value + "不是闰年";
                }
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 11月4日
  • 已采纳回答 10月27日
  • 创建了问题 10月20日

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起