jsp实现,按钮倒计时,倒计时结束后才能点击,并跳转下一页

效果图如下
请添加图片描述
话不多说,直接上代码
js内容

<script type="text/javascript">

	$(document).ready(function() {
	
		var o=$("#btn_msg");
		time(o);
	});
	var wait=2;
	function time(o){
		if (wait == 0) {
			o.removeAttr("disabled");
			o.val("下一步");  
		  } else {
			   o.attr("disabled", true);
			   o.val(wait);  
			   wait--;  
			   window.setTimeout(function() {  
			   	 	time(o)  
		   		},1000)  
		  }
	}

下面是按钮是设置

<input type="button" class="button" id="btn_msg" disabled="disabled" onclick="next()" value="下一步" />
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你解答这个问题。 首先,我们可以在 JSP 页面上创建一个表单,让用户输入他们的生日。表单中可以包含一个文本框和一个提交按钮,如下所示: ``` <form action="countdown.jsp" method="post"> <label for="birthday">请输入您的生日:</label> <input type="date" id="birthday" name="birthday"> <button type="submit">开始倒计时</button> </form> ``` 在用户提交生日后,我们需要使用 JSP 页面来处理这个请求并计算倒计时。首先,我们需要获取用户输入的生日值: ``` <% String birthday = request.getParameter("birthday"); %> ``` 接下来,我们可以使用 Java 代码来计算距离用户生日还有多少天: ``` <% DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(birthday); Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); if (cal.getTime().before(Calendar.getInstance().getTime())) { cal.set(Calendar.YEAR, year + 1); } long daysLeft = (cal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) / (24 * 60 * 60 * 1000); %> ``` 在这个代码段中,我们首先使用 SimpleDateFormat 类来将用户输入的生日字符串转换为日期对象。然后,我们可以使用 Calendar 类来获取这个日期对象中的年、月和日。接下来,我们需要将年份设置为当前年份,并检查这个日期是否在当前日期之前。如果是,我们将年份设置为下一年,以确保我们计算的是正确的天数。最后,我们使用 getTimeInMillis() 方法来计算距离用户生日还有多少毫秒,然后将其转换为天数。 最后,我们可以在 JSP 页面上展示倒计时消息: ``` <p>距离您的生日还有 <%= daysLeft %> 天!</p> ``` 完整的 JSP 页面代码如下所示: ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>生日倒计时</title> </head> <body> <h1>生日倒计时</h1> <form action="countdown.jsp" method="post"> <label for="birthday">请输入您的生日:</label> <input type="date" id="birthday" name="birthday"> <button type="submit">开始倒计时</button> </form> <% if (request.getParameter("birthday") != null) { String birthday = request.getParameter("birthday"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(birthday); Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); if (cal.getTime().before(Calendar.getInstance().getTime())) { cal.set(Calendar.YEAR, year + 1); } long daysLeft = (cal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) / (24 * 60 * 60 * 1000); %> <p>距离您的生日还有 <%= daysLeft %> 天!</p> <% } %> </body> </html> ``` 希望这个例子能够帮助你实现生日倒计时的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值