jq实现竞拍倒计时
1jq的效果代码
//全局变量用于存储当前时间
var nows; function rightZeroStr(v) {
if (v < ) {
return "" + v;
}
return v + "";
}
//计时 每10秒中为当前时间+10
setInterval(function () {
nows =parseInt(nows) + ;
}, );
//ajax.post 向服务器请求得到当前的服务器时间
function syncTime() {
var url = "Handler/Seckil.ashx?t=" + new Date().getTime();
$.post(url, { action: "now" }, function (response) {
nows = response.nows || new Date().getTime();
});
}
//倒计时 参数arg存放倒计时的标签名称 id 或者class
function lxfEndtime(arg) {
$(arg).each(function () {
var lxfday = $(this).attr("lxfday"); //用来判断是否显示天数的变量
var endtime = new Date($(this).attr("endtime")).getTime(); //取结束日期(毫秒值)
var nowtime = nows; //今天的日期(毫秒值)
var starttime = new Date($(this).attr("starttime")).getTime();
//开始时间和当时时间作比较 判断是开始 技术还是正在进行中
if (starttime >= nowtime) {
$(this).html("活动即将开始")
}
if (endtime <= nowtime) {
$(this).html("活动已经结束"); //如果结束日期小于当前日期就提示过期啦
}
if (starttime < nowtime && endtime > nowtime) {
var youtime = endtime - nowtime; //还有多久(毫秒值)
var seconds = youtime / ;
var minutes = Math.floor(seconds / );
var hours = Math.floor(minutes / );
var days = Math.floor(hours / );
var CDay = days;
var CHour = CDay * + hours % ;
var CMinute = minutes % ;
var CSecond = Math.floor(seconds % ); //"%"是取余运算,可以理解为60进一后取余数,然后只要余数。 if ($(this).attr("lxfday") == "no") {
$(this).html('<span class="countdown" millseconds="1188163453"> <strong class="tcd-h">' + CHour + '</strong>时<strong class="tcd-m">' + CMinute + '</strong>分 <strong class="tcd-s">' + CSecond + '</strong>秒 </span>'); //输出没有天数的数据
} else {
$(this).html('<span class="countdown" millseconds="1188163453"><strong class="tcd-d">' + days + '</strong><b>天</b> <strong class="tcd-h">' + CHour + '</strong> <i>:</i> <strong class="tcd-m">' + CMinute + '</strong><i>:</i> <strong class="tcd-s">' + CSecond + '</strong> </span>'); //输出有天数的数据
}
}
});
setTimeout("lxfEndtime('" + arg + "')", );
};
2用到的handler
<%@ WebHandler Language="C#" Class="Seckil" %> using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
public class Seckil : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
string action = context.Request["action"];
switch (action)
{case "now":
now(context);
return; }
context.Response.Write("Hello World");
}public void now(HttpContext context)
{
Int64 retval = ;
DateTime st = new DateTime(, , );
TimeSpan t = (DateTime.Now.ToUniversalTime() - st);
retval = (Int64)(t.TotalMilliseconds + 0.5);
context.Response.Write("{\"nows\":\"" + retval + "\"}");
} public bool IsReusable
{
get
{
return false;
}
} }
3前台页面代码
<html>
<script src="js/time.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
syncTime();
lxfEndtime(".box font");
});
</script>
<body>
<font color=\"#FF0000\" endtime=\"' + dataitem.EndDate + '\" starttime=\"' + dataitem.StartDate + '\" lxfday=\"no\"></font>
</body>
</html>
jq实现竞拍倒计时的更多相关文章
- js&jq 发送验证码倒计时
<input type="text" name='' id="btn"> //发送验证码倒计时var wait=30; function t ...
- destoon开发笔记-JQ+JS实现倒计时功能
页面代码 <div class="time " class="" id="onBidtime125" pid="125&qu ...
- JS与JQ倒计时的写法
页面需要制作一个倒计时的功能:然后度娘了一遍,找到两种写法,原生JS与JQ 的,经过测试原生JS在IE可能会有不刷新的现象所以结合了一个大神的JQ写法修改好了一个. 原生JS写法: HTML: < ...
- jq 倒计时
引入jq 注 在IE和safari 如果时间出现NAN 将时间格式改为YYYY/MM/DD HH:MM:SS 例:var d2 = new Date("2019/02/18 15:59&qu ...
- jq倒计时(代码)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- jq 实现发送验证码倒计时功能
var util = { wait:60, hsTime: function (that) { _this = this; if (_this.wait == 0) { $('#hsbtn').rem ...
- jQ效果:jQuery之插件开发短信发送倒计时功能
实现的主要功能如下: 1.点击按钮的时候,可以进行倒计时,倒计时自定义. 2.当接收短信失败后,倒计时停止,可点击重新发送短信. 3.点击的元素支持一般标签和input标签. html代码: < ...
- js,JQ获取短信验证码倒计时
按钮 <a href="javasript:void(0);"onclick="settime(this);">获取手机验证码</a> ...
- jq 某个时间段的倒计时
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- LINQ to SQL语句之Join和Order By
Join操作 适用场景:在我们表关系中有一对一关系,一对多关系,多对多关系等.对各个表之间的关系,就用这些实现对多个表的操作. 说明:在Join操作中,分别为Join(Join查询), SelectM ...
- Text Kit入门
更详细的内容可以参考官方文档 <Text Programming Guide for iOS>. “Text Kit指的是UIKit框架中用于提供高质量排版服务的一些类和协议,它让程序能够 ...
- 在windows7下配置PHP访问ICE中间件(ICE3.5.1+PHP5.4+Apache2.2 for vc9)
按照ICE的官方文档(http://doc.zeroc.com/display/Ice/Using+the+Windows+Binary+Distribution#UsingtheWindowsBin ...
- 邻接表存储图,DFS遍历图的java代码实现
import java.util.*; public class Main{ static int MAX_VERTEXNUM = 100; static int [] visited = new i ...
- 快速建立Linux c/c++编译环境
sudo apt-get install build-essential 省时又省心~
- Microsoft TFS 如何显示在Windows 的上下文菜单中
How to showing in Windows Explorer context for TFS I am not sure if this would help or you are willi ...
- 第二百八十四天 how can I 坚持
又是一个周一.今天感觉过得好艰辛啊,幸好晚上程秀通过生日请客,吃了顿大餐,还拿回了一瓶酒.哈哈. 其他也没什么了.晚上玩的挺好.不过,回来,老是渴,一直想喝水,现在是又困,又累啊,睡觉了.
- HDU 5792 World is Exploding (树状数组)
World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...
- codeforces 630KIndivisibility(容斥原理)
K. Indivisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard ...
- ASP.NET MVC程序传值方式:ViewData,ViewBag,TempData和Session
转载原地址 http://www.cnblogs.com/sunshineground/p/4350216.html 在ASP.NET MVC中,页面间Controller与View之间主要有以下几种 ...