webapi预测身高案例

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

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css">
    body,
    td,
    th {
      font-size: 12px;
    }

    a {
      color: #006699;
      text-decoration: none;
    }

    a:hover {
      color: #f60;
      text-decoration: underline;
    }

    dd,
    dl,
    ul,
    li,
    p,
    form {
      margin: 0;
      padding: 0;
      list-style-type: none;
    }

    h1,
    h2,
    h3,
    h4,
    h5 {
      font-size: 14px;
      margin: 0;
      padding: 0;
      line-height: 28px;
    }

    .but {
      color: #FF8320;
      border: 1px solid #ccc;
      background: #fff;
      cursor: pointer;
      height: 25px;
      line-height: 25px;
      width: 80px;
    }

    .checkbox {
      border: 1px solid #FFD7B7;
      margin: 5px auto;
      background: #FFFBF4;
      padding: 15px;
      width: 600px;
    }

    .Test ul {
      margin: 0;
      padding: 0;
    }

    .Test li {
      border: 1px solid #FFFBF4;
      margin-bottom: 4px;
      cursor: pointer;
      width: 100%;
      height: 30px;
      line-height: 30px;
      padding-left: 5px;
      background: #FFFBF4
    }

    .Test li.myBox {
      border: 1px solid #e7e7e7;
      background: #f7f7f7;
    }

    .Problem {}

    .hidden {
      display: none;
    }

    #Result p {
      margin: 8px;
      padding: 8px;
      line-height: 25px;
      background: #FFF;
      width: 560px;
      border: 1px dotted #FF8E20;
    }

    #Result i {
      color: red;
      font-size: 16px;
      font-style: normal;
    }

    #fu,
    #mu {
      color: #ccc;
    }
  </style>
  <div class="checkbox">
    <div class="Test">
      <div id="Problem">
        <h3>儿童身高预测</h3>
        <form action="" method="get">
          <ul>
            <li>儿童性别:<input name="gender" type="radio">男孩<input name="gender" type="radio"> 女孩 </li>

            <li>爸爸的身高:<input type="text" size="8" maxlength="8" id="fu" fu="例:175" placeholder="例:175"> 厘米</li>

            <li>妈妈的身高:<input type="text" size="8" maxlength="8" id="mu" mu="例:165" placeholder="例:165"> 厘米</li>
          </ul>
          <input type="button" class="but" id="btn" value="查看结果" />
          <input type="button" class="but" id="reset" value="重新测试" onclick="" />
        </form>
      </div>

      <div id="Result">
        <h3>测试结果</h3>
        <p>
          小孩未来的身高是:<i id="Result2">未知</i> 厘米
        </p>
      </div>
    </div>
  </div>
  <script type="text/javascript">

  </script>

  注解:<br> 儿子成年身高=[(父身高+母身高)/2]×1.08

  <br> 女儿成年身高=(父身高×0.923+母身高)

  <br> 错误提示有提示:

  <br> 没选择儿童性别!
  <br> 输入父母身高不是数字!
  <br>
  <font color="red">输入父母身高要都是55-250之间!</font> <br>


  <script>
    // 获取查看结果
    let ckjg = document.querySelectorAll('.but')[0]
    // 获取重新测试
    let cxcs = document.querySelectorAll('.but')[1]
    // 获取性别男
    let boy = document.querySelectorAll('input')[0]
    // 获取性别女
    let girl = document.querySelectorAll('input')[1]

    let ul = document.querySelector('ul')

    // 获取结果框
    let jg = document.querySelector('#Result2')
    let fu;
    let mu;
    // 给参考结果绑定点击事件
    ckjg.addEventListener('click', function () {
      // 获取爸爸身高
      fu = document.querySelectorAll('input')[2].value
      // 获取妈妈身高
      mu = document.querySelectorAll('input')[3].value

      if (fu <= 250 && mu <= 250 && fu >= 50 && mu >= 50) {
        if (boy.checked) {

          jg.innerHTML = Math.round(((+fu + +mu) / 2) * 1.08)

        }
        else if (girl.checked) {

          jg.innerHTML = Math.round((+fu * 0.923 + mu))

        } else {
          alert('没选择儿童性别!请重新选择')
        }
      } else {
        alert('输入父母身高要都是55-250之间')
      }
    })


    // 重新测试
    cxcs.addEventListener('click', function () {
      document.querySelectorAll('input')[2].value = ''
      document.querySelectorAll('input')[3].value = ''
      let radio = ul.children[0].querySelectorAll('input')

      for (let i = 0; i < radio.length; i++) {
        radio[i].checked = false
      }
    })


  </script>
  </body>

</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值