• 实现携程X分钟前有人预定功能


    实现携程X分钟前有人预定功能

    原理:利用cookie与计时器两部分;

        首先,进入页面,x会被随机数赋值,赋值后x会一分钟加1,直到加到60,再从1开始累加。

        页面是否相同是根据页面的url后的id值判断;

        

    <span id='myspan'></span>   x分钟前有人预定该景点

    <script>
    $(document).ready(function() {
    if (window.location.href.includes('?')) {      
    if (window.location.href.split('?')[1].split('=')[0] === 'id') {
    var ids = window.location.href.split('?')[1].split('=')[1];
    var date = new Date();
    date.setTime(date.getTime() + ( 600*1000));
    //console.log(decodeURI(ids));
    //console.log($.cookie('cookie_urlId'));
    urlId = decodeURI(ids); //url的id值
    if ($.cookie('cookie_urlId') === urlId) {
    console.log(true);

    //随机数代码
    if ($.cookie('redomnum' + urlId) === undefined) {
    //console.log($.cookie('redomnum'));
    var num = parseInt(60*Math.random());
    if (num === 0) {
    num = 1;
    }
    $('#myspan').text(num);
    $.cookie('redomnum' + urlId, num, { express: date });
    } else {
    $('#myspan').text($.cookie('redomnum' + urlId));
    };
    } else {
    $.cookie('cookie_urlId', urlId, { express: date });

    //随机数代码
    if ($.cookie('redomnum' + urlId) === undefined) {
    //console.log($.cookie('redomnum'));
    var num = parseInt(60*Math.random());
    if (num === 0) {
    num = 1;
    }
    $('#myspan').text(num);
    $.cookie('redomnum' + urlId, num, { express: date });
    } else {

    $('#myspan').text($.cookie('redomnum' + urlId));
    }
    }

    sendMessage();

    function sendMessage(){
    window.setInterval(SetReminTime,1000 * 60);
    }
    function SetReminTime(){
    var num = $.cookie('redomnum' + urlId);
    if(num === '60'){
    num = 0;
    }
    $.cookie('redomnum' + urlId, ++num, { express: date });
    $('#myspan').text($.cookie('redomnum' + urlId));
    }
    }
    }
    });


    </script>

  • 相关阅读:
    struct--file_operations
    接触到的一些数据结构: LIST_ENTRY, TAILQ
    Kernel Mode, User Mode
    可运行的代码
    写一篇Hook Driver.
    Chromium学习笔记
    Resources for Browser/Webkit/GPU
    Win7/8, convert dynamic disk volume to basic volume.
    System and Device power management.
    错误记录1----dom4j解析xml调试编码错误
  • 原文地址:https://www.cnblogs.com/webzwf/p/5784773.html
Copyright © 2020-2023  润新知