使用chatgpt生成一个签证有效期在线计算器

编程知识 更新时间:2023-05-02 22:31:51

示例页面,亲测chatgpt生成的代码可用,太强大了

https://www.goodtools.xyz/cn/t/visavalidity.php

一直困扰于计算方法,没想到几秒钟就做好了,太强大了。chatgpt生成的代码如下:

HTML:

```
<!DOCTYPE html>
<html>
<head>
    <title>计算签证有效期</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div class="container">
        <h1>计算签证有效期</h1>
        <form>
            <label for="startDate">入境日期:</label>
            <input type="date" id="startDate">
            <label for="validDays">签证有效期:</label>
            <input type="number" id="validDays" placeholder="请输入签证有效期(天)">
            <button type="button" onclick="calculate()">计算</button>
        </form>
        <div id="result"></div>
    </div>

    <script src="app.js"></script>
</body>
</html>
```

CSS:

```
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
}

form {
    margin-bottom: 20px;
}

label {
    display: inline-block;
    width: 120px;
}

input[type="date"], input[type="number"] {
    width: 200px;
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

button {
    padding: 6px 12px;
    background-color: #4CAF50;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #3e8e41;
}

#result {
    margin-top: 20px;
    font-size: 20px;
    text-align: center;
}
```

JavaScript:

```
function calculate() {
  const startDateInput = document.getElementById("startDate");
  const validDaysInput = document.getElementById("validDays");
  const startDate = new Date(startDateInput.value);
  const validDays = parseInt(validDaysInput.value);
  if (startDate && validDays) {
    const leavingDate = new Date(startDate.getTime() + validDays * 24 * 60 * 60 * 1000);
    const resultDiv = document.getElementById("result");
    resultDiv.innerHTML = `您应该在${leavingDate.getFullYear()}年${leavingDate.getMonth() + 1}月${leavingDate.getDate()}日前离境。`;
  } else {
    alert("请输入完整的信息。");
  }
}
```

更多推荐

使用chatgpt生成一个签证有效期在线计算器

本文发布于:2023-04-29 02:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/8f089e289dad7e5e344d2a393761ee15.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   计算器   签证   有效期   chatgpt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 109979文章数
  • 27954阅读数
  • 0评论数