验证日期的开始和结束(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
满意答案
K8只有64位执行单元,因此每128b指令被解码为2个m-ops。 此外,即使地址对齐,
movups
也比movaps
更多。 (虽然根据Agner Fog的表格,它仍然与movaps
每2周期吞吐量movaps
。)如果您在标量版本中使用了分支,并且
min
和max
不经常更改,则分支预测可以使其运行得非常快。这是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 thanmovaps
even when the address is aligned. (Although according to Agner Fog's tables, it still has the same one per 2 cycle throughput asmovaps
.)If you used branches in the scalar version, and the
min
andmax
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?)
第一个/最后一个与最小值/最大值(first/ last vs min/max. ORACLE. SQL)
TIMESTAMPDIFF MIN MAX优化(TIMESTAMPDIFF MIN MAX optimization)
寻找最大的问题(Finding Max Question)
寻找大熊猫班级的最小(或最大)(Finding the min (or max) of a class in Pandas)
从数组中获取Min和Max(Getting Min and Max from array)
寻找最小/最大(Finding min/max. Optimization)
如何在Android Java中创建一个介于最小和最大之间的随机数,不包括介于最小和最大之间的一些数字?(How to create in Android Java a random number between min and max excluding some numbers that fall between min and max.?)
寻找最小必要体积的气体容器(Finding minimum necessary volume of gas container)
优化函数以查找最小和最大元素(Optimization of a function to find min and max element)
相关文章
更多Solr DIH Quick Start
getting start with storm 翻译 第二章 part-1
Hadoop1.0.3的start-dfs.sh系列脚本分析
Hadoop学习笔记(一)HBase脚本分析(一)start-hbase.sh
项目移到linux环境下时tomcat报错 java.util.zip.ZipException: invalid END header
getting start with storm 翻译 第八章 part-2
启动Solr服务报错:Path must not end with / character
How to Start a Business in 10 Days
Storm 【开发细节】 - geting Start with Storm
关于Thread类中的start()方法和run()方法
最新问答
更多您如何使用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?)
将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
在计算机拍照在哪里进入
使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
单页应用程序:页面重新加载(Single Page Application: page reload)
在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!