<div class="form-group box" id="quarter"style="width:480px;margin: 20px 0;height:35px"> <label for="dtp_input3" class="col-xs-3 control-label" style="vertical-align:middle;line-height:35px">选择季度:</label> <div class="input-group col-xs-6" data-date="" data-date-format="hh:ii" data-link-field="dtp_input3" data-link-format="hh:ii" style="width:150px;vertical-align:middle" > <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span> <input class="form-control form_QT" size="16" type="text" value="" id="qt_1" style="width:250px" class='quarterDate'> </div> <input type="hidden" id="dtp_input3" value="" /><br/> </div>让上面这段代码在刚渲染后默认显示当前时间的上一个季度,当选择时间是还是显示自己选择的季度,不要用moment处理
时间: 2023-07-03 16:25:11 浏览: 104
可以使用JavaScript中的Date对象来处理季度的计算。首先获取当前时间,然后将月份减去1,再将月份除以3向下取整,得到当前所在季度的序号。最后将季度序号减1即可得到上一个季度的序号。
以下是实现代码:
// 获取当前时间
var currentDate = new Date();
// 获取当前季度的序号
var currentQuarter = Math.floor((currentDate.getMonth() + 1) / 3);
// 获取上一个季度的序号
var previousQuarter = currentQuarter - 1;
// 如果当前是第一季度,则上一个季度是去年的第四季度
if (previousQuarter < 1) {
previousQuarter = 4;
}
// 将上一个季度的序号转换为字符串,补0成两位数
previousQuarter = ('0' + previousQuarter).slice(-2);
// 将上一个季度的起始日期设置为当前时间的上一个季度
var previousQuarterStartDate = new Date(currentDate.getFullYear(), (previousQuarter - 1) * 3, 1);
// 将上一个季度的结束日期设置为当前时间的本季度的第一天减1毫秒
var previousQuarterEndDate = new Date(currentDate.getFullYear(), (previousQuarter * 3), 1);
previousQuarterEndDate = new Date(previousQuarterEndDate.getTime() - 1);
// 将起始日期和结束日期格式化成字符串,以便填充到表单中
var previousQuarterStartDateString = previousQuarterStartDate.getFullYear() + '-' + ('0' + (previousQuarterStartDate.getMonth() + 1)).slice(-2) + '-' + ('0' + previousQuarterStartDate.getDate()).slice(-2);
var previousQuarterEndDateString = previousQuarterEndDate.getFullYear() + '-' + ('0' + (previousQuarterEndDate.getMonth() + 1)).slice(-2) + '-' + ('0' + previousQuarterEndDate.getDate()).slice(-2);
// 将起始日期和结束日期分别填充到表单的两个输入框中
document.getElementById('qt_1').value = previousQuarterStartDateString + ' - ' + previousQuarterEndDateString;
需要注意的是,这段代码中计算季度的方式是将月份除以3向下取整,这不是绝对准确的计算方法。例如,如果当前时间是3月1日,按照这种方法计算出来的季度是1,但3月份实际上是属于第一季度的。如果要完全准确地计算季度,可以考虑使用moment库或其他日期处理库。
相关推荐









<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>注册页面</title> <style> /容器/ .container{ max-width: 400px; margin: 0 auto; text-align: center; margin-top: 100px; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 5px #ddd; } /表单组/ .form-group{ margin-bottom: 20px; text-align: left; } /表单组标签/ .form-group label{ display: inline-block; width: 70px; font-weight: bold; } /表单组输入框/ .form-group input{ display: inline-block; width: 200px; height: 30px; border-radius: 3px; border: 1px solid #ccc; padding: 5px 10px; } /输入框获取焦点时边框颜色/ .form-group input:focus{ outline: none; border-color: #1E90FF; } /按钮组/ .button-group input{ margin-right: 10px; background-color: #1E90FF; color: #fff; border: none; border-radius: 3px; padding: 5px 20px; font-weight: bold; } /按钮悬停时背景颜色和不透明度/ .button-group input:hover{ cursor: pointer; opacity: 0.8; } /注册组/ .register-group a{ font-size: 12px; text-decoration: none; text-align: right; color: black; } /注册链接悬停时文字下划线/ .register-group a:hover{ text-decoration: underline; } </style> </head> <body> <span> <form action="servletControllRegister" method="post"> <span> <label for="uname">用户名:</label> <input type="text" id="uname" name="uname"/> span> <span> <label for="upwd">密码:</label> <input type="password" id="upwd" name="upwd"/> span> <span> <input type="submit" value="注册"/> <input type="reset" value="重置"/> span> <span> 已有账号?点击登录 span> </form> span> </body> </html>是jsp页面

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>用户登录</title> <style> /* 基础样式 */ body { font-family: 'Arial', sans-serif; background-color: #f0f2f5; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .login-container { background: white; padding: 40px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 350px; } h2 { color: #1a73e8; text-align: center; margin-bottom: 30px; } .form-group { margin-bottom: 20px; } label { display: block; margin-bottom: 8px; color: #5f6368; } input[type="text"], input[type="password"] { width: 100%; padding: 12px; border: 1px solid #dadce0; border-radius: 4px; box-sizing: border-box; font-size: 16px; } input[type="submit"] { background-color: #1a73e8; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; width: 100%; font-size: 16px; transition: background-color 0.3s; } input[type="submit"]:hover { background-color: #1557b0; } .links { text-align: center; margin-top: 20px; } .links a { color: #1a73e8; text-decoration: none; font-size: 14px; margin: 0 10px; } </style> </head> <body> <span> <span>用户登录span> <form action="/login" method="POST"> <span> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> span> <span> <label for="password">密码:</label> <input type="password" id="password" name="password" required> span> <input type="submit" value="登录"> </form> <span> 忘记密码? 注册账号 span> span> </body> </html>这是网页前端代码,可以不用后端,基于nginx在点击的时候返回一个404,因为我的目的是监听网页

选题1:网络监听与https的配置 任务内容 利用软件对特定Web系统的前端与后端的通信进行监听;配置 Web服务器启用https,验证https对抗网络监听的作用 任务目的 体验通信信道存在信息泄露安全风险;掌握基于SSL的https服务器配置方 法 参考方法 ①查阅资料了解网络嗅探、网络监听的基本原理与方法,了解网络通信协议,熟悉网络通信数据的抓包方法与数据包的分析方法;②设计实现一个Web系统的登录功能,并基于nginx部署Web系统,“打开登录界面,“提交登录信息,用Wireshark或其它抓包软件,分析登录界面向后台发送的数据包中的账号和密码;③申请SSL证书和密钥,在nginx中配置SSL,重启nginx后再次登录、抓包分析。我是windows系统,不会配置nginx,现在只有一个前端的代码,可以不用后端吗,以下是我的login.html文件的代码:<!DOCTYPE html> <html lang=“zh-CN”> <head> <meta charset=“UTF-8”> <title>用户登录</title> <style> /* 基础样式 */ body { font-family: ‘Arial’, sans-serif; background-color: #f0f2f5; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .login-container { background: white; padding: 40px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 350px; } h2 { color: #1a73e8; text-align: center; margin-bottom: 30px; } .form-group { margin-bottom: 20px; } label { display: block; margin-bottom: 8px; color: #5f6368; } input[type=“text”], input[type=“password”] { width: 100%; padding: 12px; border: 1px solid #dadce0; border-radius: 4px; box-sizing: border-box; font-size: 16px; } input[type=“submit”] { background-color: #1a73e8; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; width: 100%; font-size: 16px; transition: background-color 0.3s; } input[type=“submit”]:hover { background-color: #1557b0; } .links { text-align: center; margin-top: 20px; } .links a { color: #1a73e8; text-decoration: none; font-size: 14px; margin: 0 10px; } </style> </head> <body> <span> <span>用户登录span> <form action=“/login” method=“POST”> <span> <label for=“username”>用户名:</label> <input type=“text” id=“username” name=“username” required> span> <span> <label for="password">密码:</label> <input type="password" id="password" name="password" required> span> <input type="submit" value="登录"> </form> <span> 忘记密码? 注册账号 span> span> </body> </html>








