验证日期的开始和结束(validating dates start and end)

我想验证我的出发和退货日期。

目前,您可以选择从今天开始的任何日期。

我需要的是返回日期中显示的日期,以禁用在开始日期之前显示或被选中的任何日期。

我的HTML

<input class="fromDate" data-date-format="dd/mm/yyyy" data-val="true" data-val-required="[Required_DepartureDate] not found" id="DepartureDate" name="d" type="text" value="">
<input class="ToDate" data-date-format="dd/mm/yyyy" id="ReturnDate" name="d" type="text" value="">

我的jquery

 /* global google */
define(["jquery",
"modernizr",
"plugin/bootstrap-datepicker",
"plugin/bootstrap-datepicker.ar",
"plugin/bootstrap-datepicker.zh-CN"]
, function ($, Modernizr) {

    /**
     * D picker - a wrapper around datepicker with a bit of feature detection
     */
    $.fn.dPicker = function () {

        var htmlLang = $("html").attr("lang"),
            langObj = $.fn.datepicker.dates[htmlLang];

        if (langObj === undefined || langObj === null) {
            if(htmlLang.indexOf("-") > -1)
            {
                htmlLang = htmlLang.substring(0, htmlLang.indexOf("-"));
                langObj = $.fn.datepicker.dates[htmlLang];
            }
        }

        // If the language still isn't found the look for one matching the first part of the lang string
        if (langObj === undefined || langObj === null && htmlLang.indexOf("-") === -1) {
            for (var key in $.fn.datepicker.dates) {
                if (key.indexOf(htmlLang) === 0) {
                    htmlLang = key;
                    langObj = $.fn.datepicker.dates[key];
                    break;
                }
            }
        }

        var fromDate = {
            format: "dd/mm/yyyy",
            startDate: '1',//min date set to today
            autoclose: true,
            todayHighlight: true,
            language: langObj === undefined || langObj === null ? "en" : htmlLang,
            orientation: langObj === undefined || langObj === null || !langObj.rtl ? "auto auto" : "auto right",
            clearBtn : true
        };


        var toDate = {
            format: "dd/mm/yyyy",
            startDate: '1',//Set date x days from today
            maxDate: '+1y +1d',//max date x year + 1 day
            endDate: '+1y +1d',
            autoclose: true,
            todayHighlight: true,
            language: langObj === undefined || langObj === null ? "en" : htmlLang,
            orientation: langObj === undefined || langObj === null || !langObj.rtl ? "auto auto" : "auto right",
            clearBtn: true
        };


        return this.each(function (i, el) {

            var $that = $('.fromDate');
            var $this = $('.ToDate');

            if (!Modernizr.touch || !Modernizr.inputtypes.date) {
                //if (Modernizr.inputtypes.date) {
                    // Only swap the input type to text because IE8 doesn't allow changing types (throws error)
                    // We do this so that the placeholder shows in browsers that support it
                    //$that.attr("type", "text");
                //}

                try {
                    $that.attr("type", "text");
                    $this.attr("type", "text");
                } catch (e) {
                }

                // add localised date format from data attribute
                if ($that.data("date-format")) {
                    fromDate.format = $that.data("date-format");
                }

                if ($this.data("date-format")) {
                    toDate.format = $this.data("date-format");
                }

                // copy name attribute from $that.datepicker(dpOpts);
                // Insert hidden field & remove name attribute from textbox
                $that.after("<input name='" + $that.attr("name") + "' type='hidden'>")
                    .attr("name", "d")
                    .datepicker(fromDate)
                    .on("changeDate", function (e) {
                        $(this).next().val(e.format(0, "yyyy-mm-dd"));
                    });

                if ($that.val() !== "") {
                    $that.datepicker("setDate", new Date($that.val()));
                }


                $this.after("<input name='" + $this.attr("name") + "' type='hidden'>")
                    .attr("name", "d")
                    .datepicker(toDate)
                    .on("changeDate", function (e) {
                        $(this).next().val(e.format(0, "yyyy-mm-dd"));
                    });

                if ($this.val() !== "") {
                    $this.datepicker("setDate", new Date($this.val()));
                }

                // re-run validation after changing name attribute, see http://stackoverflow.com/a/18063874/486434
                var $form = $that.closest("form");
                var $form2 = $this.closest("form");
                $form.unbind();
                $form2.unbind();
                $form.data("validator", null);
                $form2.data("validator", null);
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                $form2.validate($form2.data("unobtrusiveValidation").options);
            }


        });
    };

    return $.fn.dPicker;
});

I am trying to validate my Departure and Return dates.

At the moment you can select any dates starting from today onwards.

what I need is the dates shown in the return date to disable any dates from showing or being selected before the start date.

my html

<input class="fromDate" data-date-format="dd/mm/yyyy" data-val="true" data-val-required="[Required_DepartureDate] not found" id="DepartureDate" name="d" type="text" value="">
<input class="ToDate" data-date-format="dd/mm/yyyy" id="ReturnDate" name="d" type="text" value="">

my jquery

 /* global google */
define(["jquery",
"modernizr",
"plugin/bootstrap-datepicker",
"plugin/bootstrap-datepicker.ar",
"plugin/bootstrap-datepicker.zh-CN"]
, function ($, Modernizr) {

    /**
     * D picker - a wrapper around datepicker with a bit of feature detection
     */
    $.fn.dPicker = function () {

        var htmlLang = $("html").attr("lang"),
            langObj = $.fn.datepicker.dates[htmlLang];

        if (langObj === undefined || langObj === null) {
            if(htmlLang.indexOf("-") > -1)
            {
                htmlLang = htmlLang.substring(0, htmlLang.indexOf("-"));
                langObj = $.fn.datepicker.dates[htmlLang];
            }
        }

        // If the language still isn't found the look for one matching the first part of the lang string
        if (langObj === undefined || langObj === null && htmlLang.indexOf("-") === -1) {
            for (var key in $.fn.datepicker.dates) {
                if (key.indexOf(htmlLang) === 0) {
                    htmlLang = key;
                    langObj = $.fn.datepicker.dates[key];
                    break;
                }
            }
        }

        var fromDate = {
            format: "dd/mm/yyyy",
            startDate: '1',//min date set to today
            autoclose: true,
            todayHighlight: true,
            language: langObj === undefined || langObj === null ? "en" : htmlLang,
            orientation: langObj === undefined || langObj === null || !langObj.rtl ? "auto auto" : "auto right",
            clearBtn : true
        };


        var toDate = {
            format: "dd/mm/yyyy",
            startDate: '1',//Set date x days from today
            maxDate: '+1y +1d',//max date x year + 1 day
            endDate: '+1y +1d',
            autoclose: true,
            todayHighlight: true,
            language: langObj === undefined || langObj === null ? "en" : htmlLang,
            orientation: langObj === undefined || langObj === null || !langObj.rtl ? "auto auto" : "auto right",
            clearBtn: true
        };


        return this.each(function (i, el) {

            var $that = $('.fromDate');
            var $this = $('.ToDate');

            if (!Modernizr.touch || !Modernizr.inputtypes.date) {
                //if (Modernizr.inputtypes.date) {
                    // Only swap the input type to text because IE8 doesn't allow changing types (throws error)
                    // We do this so that the placeholder shows in browsers that support it
                    //$that.attr("type", "text");
                //}

                try {
                    $that.attr("type", "text");
                    $this.attr("type", "text");
                } catch (e) {
                }

                // add localised date format from data attribute
                if ($that.data("date-format")) {
                    fromDate.format = $that.data("date-format");
                }

                if ($this.data("date-format")) {
                    toDate.format = $this.data("date-format");
                }

                // copy name attribute from $that.datepicker(dpOpts);
                // Insert hidden field & remove name attribute from textbox
                $that.after("<input name='" + $that.attr("name") + "' type='hidden'>")
                    .attr("name", "d")
                    .datepicker(fromDate)
                    .on("changeDate", function (e) {
                        $(this).next().val(e.format(0, "yyyy-mm-dd"));
                    });

                if ($that.val() !== "") {
                    $that.datepicker("setDate", new Date($that.val()));
                }


                $this.after("<input name='" + $this.attr("name") + "' type='hidden'>")
                    .attr("name", "d")
                    .datepicker(toDate)
                    .on("changeDate", function (e) {
                        $(this).next().val(e.format(0, "yyyy-mm-dd"));
                    });

                if ($this.val() !== "") {
                    $this.datepicker("setDate", new Date($this.val()));
                }

                // re-run validation after changing name attribute, see http://stackoverflow.com/a/18063874/486434
                var $form = $that.closest("form");
                var $form2 = $this.closest("form");
                $form.unbind();
                $form2.unbind();
                $form.data("validator", null);
                $form2.data("validator", null);
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                $form2.validate($form2.data("unobtrusiveValidation").options);
            }


        });
    };

    return $.fn.dPicker;
});

原文:https://stackoverflow.com/questions/28193512
2021-04-18 16:04

满意答案

K8只有64位执行单元,因此每128b指令被解码为2个m-ops。 此外,即使地址对齐, movups也比movaps更多。 (虽然根据Agner Fog的表格,它仍然与movaps每2周期吞吐量movaps 。)

如果您在标量版本中使用了分支,并且minmax不经常更改,则分支预测可以使其运行得非常快。

这是SIMD必须做更多工作的情况之一,它实际上比标量慢。 虽然这个SSE2版本实际上可能比具有全宽矢量单位的CPU上的标量更好,例如K10或Merom。 (或更新)

当然,使用SSE4.1 pmaxsd / pminsd可以获得更好的结果。


K8 only has 64bit execution units, so every 128b instruction is decoded into 2 m-ops. Also, movups is more m-ops than movaps even when the address is aligned. (Although according to Agner Fog's tables, it still has the same one per 2 cycle throughput as movaps.)

If you used branches in the scalar version, and the min and max don't change often, then branch prediction can make it run quite fast.

This is one of those cases where SIMD has to do so much more work that it's actually slower than scalar. Although this SSE2 version might actually be better than scalar on CPUs with full-width vector units, like K10 or Merom. (or newer)

Of course, you'd get far better results with SSE4.1 pmaxsd/pminsd.

相关问答

更多

如何查找最大值(How to find max. and min. in array using minimum comparisons?)

1. Pick 2 elements(a, b), compare them. (say a > b) 2. Update min by comparing (min, b) 3. Update max by comparing (max, a) 这样你可以对2个元素进行3次比较,相当于N元素的总共3N/2次比较。 1. Pick 2 elements(a, b), compare them. (say a > b) 2. Update min by comparing (min, b) 3. ...

第一个/最后一个与最小值/最大值(first/ last vs min/max. ORACLE. SQL)

基于您的标签,我假设您在Oracle中: KEEP语句的示例。 EMPNO | DEPTNO | SAL | LOWEST | HIGHEST 7934 | 10 | 1300 | 1300 | 5000 7782 | 10 | 2450 | 1300 | 5000 7839 | 10 | 5000 | 1300 | 5000 7369 | 20 | 800 | 800 | 3000 7876 | 20 ...

TIMESTAMPDIFF MIN MAX优化(TIMESTAMPDIFF MIN MAX optimization)

尝试调整查询以使用现代连接语法 SELECT ... FROM tracking JOIN sessions ON sessions.session_ID = tracking.session_ID LEFT JOIN composer_sessions ON sessions.IP = composer_sessions.IP WHERE composer_sessions.IP IS NULL AND tracking.tour_ID = '102098' GROUP B...

寻找最大的问题(Finding Max Question)

假设所有的图层都是相同的尺寸sizeX ×尺寸sizeY ,否则这是没有意义的: var maxLayer = new Double[sizeX,sizeY]; for( int x = 0; x <= maxLayer.GetUpperBound(0); x++ ) for( int y = 0; y <= maxLayer.GetUpperBound(1); y++ ) maxLayer[x,y] = Double.NegativeInfinity; foreach...

寻找大熊猫班级的最小(或最大)(Finding the min (or max) of a class in Pandas)

通过使用transform df['min']=df.groupby('class')['value'].transform('min') df Out[497]: class value min 0 1 6 4 1 1 4 4 2 1 5 4 3 5 6 2 4 5 2 2 By using transform df['min']=df.groupby(...

从数组中获取Min和Max(Getting Min and Max from array)

你的代码错了。 这里有一点改进: Scanner in=new Scanner (System.in); double num[]=new double[5]; double average=0; int i=0; double sum=0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (i=0;i<num.length;i++) { System.out.println("enter a numb...

寻找最小/最大(Finding min/max. Optimization)

K8只有64位执行单元,因此每128b指令被解码为2个m-ops。 此外,即使地址对齐, movups也比movaps更多。 (虽然根据Agner Fog的表格,它仍然与movaps每2周期吞吐量movaps 。) 如果您在标量版本中使用了分支,并且min和max不经常更改,则分支预测可以使其运行得非常快。 这是SIMD必须做更多工作的情况之一,它实际上比标量慢。 虽然这个SSE2版本实际上可能比具有全宽矢量单位的CPU上的标量更好,例如K10或Merom。 (或更新) 当然,使用SSE4.1 p...

如何在Android Java中创建一个介于最小和最大之间的随机数,不包括介于最小和最大之间的一些数字?(How to create in Android Java a random number between min and max excluding some numbers that fall between min and max.?)

这是我的AndroidActivity代码,它的工作原理。 package com.androidbook.droid1; import java.util.Random; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; public class Dr...

寻找最小必要体积的气体容器(Finding minimum necessary volume of gas container)

最小生成树具有编码顶点之间的所有路径的整洁属性,其最小化路径上最长边的长度。 对于Euclidean MST,您可以计算Delaunay三角剖分,然后运行您最喜欢的O(m log n)时间算法(在m = O(n)边的图上),总运行时间为O(n log n)。 或者,您可以使用具有良好常量的O(n ^ 2)-time算法运行具有天真优先级队列的Prim(特别是如果您利用SIMD)。 The minimum spanning tree has the neat property of encoding...

优化函数以查找最小和最大元素(Optimization of a function to find min and max element)

找到最小值或最大值或最小值和最大值的复杂度始终为O(n) 。 如果阵列必须保持未排序,则无法改进。 使用您的原始方法 通过巧妙地结合搜索最小和最大值同时使用稍微改进的算法,您可以最终提高性能,如本文所述 。 然后,您将在每次最小/最大搜索时节省n / 2-2比较。 但这不会改变每次搜索的O(n)的数量级。 所以整体算法将保持在O(n²)。 替代尊重您的方法 另一种方法是使用指向未排序表中元素的阴影排序数据结构。 这里是基于标准向量和算法的实现: vector<int*> myshadow(n); ...

相关文章

更多

Solr DIH Quick Start

Step 1 : Edit your solrconfig.xml to add the reques ...

getting start with storm 翻译 第二章 part-1

转载请注明出处:http://blog.csdn.net/lonelytrooper/article/ ...

Hadoop1.0.3的start-dfs.sh系列脚本分析

熟悉脚本的启动过程,也就熟悉了Hadoop的执行过程。所以研究并学习hadoop的脚本启动过程是非常有 ...

Hadoop学习笔记(一)HBase脚本分析(一)start-hbase.sh

HBase 脚本流程: 相关阅读:Hadoop学习笔记(一)HBase脚本分析(二)hbase-dae ...

项目移到linux环境下时tomcat报错 java.util.zip.ZipException: invalid END header

我把我的一个windows环境下的项目移到linux环境下时tomcat报错,报错如下: java. ...

getting start with storm 翻译 第八章 part-2

转载请注明出处:http://blog.csdn.net/lonelytrooper/article/ ...

启动Solr服务报错:Path must not end with / character

今天在第一次对Solr的UI Console进行Add Core操作的时候,用了默认选项,提交后页面无 ...

How to Start a Business in 10 Days

With an executive staffing venture about to open, a ...

Storm 【开发细节】 - geting Start with Storm

packagetest;importjava.io.IOException;importjava.ut ...

关于Thread类中的start()方法和run()方法

引用 public void start() Causes this thread to ...

最新问答

更多

您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)

将diff文件复制到存储库的根目录,然后执行以下操作: git apply yourcoworkers.diff 有关apply命令的更多信息, apply 见其手册页 。 顺便说一下:一个更好的方法是通过文件交换整个提交文件是发送者上的命令git format-patch ,然后在接收器上加上git am ,因为它也传送作者信息和提交信息。 如果修补程序应用程序失败,并且生成diff的提交实际上在您的备份中,则可以使用尝试在更改中合并的apply程序的-3选项。 它还适用于Unix管道,如下

将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)

尝试将第二行更改为snprintf(buf1, sizeof buf1, "%.2f", balance1); 。 另外,为什么要声明用该特定表达式分配缓冲区的存储量? EDIT @LưuVĩnhPhúc在下面的评论中提到我的原始答案中的格式说明符将舍入而不是截断,因此根据如何在不使用C舍入的情况下截断小数,您可以执行以下操作: float balance = 200.56866; int tmp = balance1 * 100; float balance1 = tmp / 100.0; c

OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)

这是简单的解决方案 在你需要写的控制器中 BackendMenu::setContext('Archetypics.Team', 'website', 'team'); 请参阅https://octobercms.com/docs/backend/controllers-views-ajax#navigation-context BackendMenu::setContext('Author.Plugin name', 'Menu code', 'Sub menu code'); 你需要在r

页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)

每当发出请求时ASP都会创建一个新的Page对象,并且一旦它将响应发送回用户就不会保留对该Page对象的引用,因此只要你找不到某种方法来保持生命自己引用该Page对象后,一旦发送响应, Page和只能通过该页面访问的所有对象才有资格进行垃圾回收。 ASP creates a new Page object whenever a request is made, and it does not hold onto the reference to that Page object once it

codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)

要在生产服务器中调试这个,你可以临时放 error_reporting(E_ALL); 并查看有哪些其他错误阻止正确的重定向。 您还应该检查生产服务器发送的响应标头。 它是否具有“缓存”,是否需要重新验证标头等 to debug this in production server, you can temporary put error_reporting(E_ALL); and see what other errors are there that prevents the proper

在计算机拍照在哪里进入

打开娥的电脑.在下面找到视频设备点击进去就可以了...

使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)

你是对的。 第一次输入后,换行符将保留在输入缓冲区中。 第一次读取后尝试插入: cin.ignore(); // to ignore the newline character 或者更好的是: //discards all input in the standard input stream up to and including the first newline. cin.ignore(numeric_limits::max(), '\n'); 您必须为#inc

No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)

for (int k = 0; k > 10; k++) { System.out.println(k); } k不大于10,所以循环将永远不会执行。 我想要什么是k<10 ,不是吗? for (int k = 0; k < 10; k++) { System.out.println(k); } for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop

单页应用程序:页面重新加载(Single Page Application: page reload)

优点是不注销会避免惹恼用户,以至于他们会想要杀死你:-)。 说真的,如果每次刷新页面时应用程序都会将我注销(或者在新选项卡中打开一个链接),我再也不会使用该应用程序了。 好吧,不要这样做。 确保身份验证令牌存储在刷新后的某个位置,即不在某些JS变量中,而是存储在cookie或本地存储中。 The advantage is that not logging off will avoid pissing off your users so much that they'll want to kill

在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)

EXECUTE IMMEDIATE 'SELECT '||field_val_temp ||' FROM tableb WHERE function_id = :func_val AND rec_key = :rec_key' INTO field_val USING 'STDCUSAC' , yu.rec_key; 和, EXECUTE IMMEDIATE 'UPDATE tablec SET field_val_'||i||' = :field_val' USI