jQuery技术:jqueryvalidation将来的日期addMethod();

jqueryvalidation插件的一些问题,以及将来的日期。

我有一个像这样的输入字段:

 

拜托, 我不想要的日期选择 ! 只有这样的面具:

  $("#datefuture").mask('99/99/9999', {placeholder:'_'}); 

对于validate插件我试试这个addMethod(); 但它不起作用,我希望有人可以帮助我。

 $.validator.addMethod("minDate", function(value, element) { var now = new Date(); var myDate = new Date(value); var mD = ("0" + (myDate.getDate())).slice(-2) + '/' + ("0" + (myDate.getMonth()+1)).slice(-2) + '/' + myDate.getFullYear(); var nowdate = ("0" + (now.getDate())).slice(-2) + '/' + ("0" + (now.getMonth()+1)).slice(-2) + '/' + now.getFullYear(); return this.optional(element) || mD > nowdate; // else alert('Das passt nicht!' + mD + ' ' + nowdate); }); 

    您可以直接比较日期,不需要进行所有连接。

     jQuery.validator.addMethod("minDate", function (value, element) { var now = new Date(); var myDate = new Date(value); return this.optional(element) || myDate > now; // else alert('Das passt nicht!' + mD + ' ' + nowdate); }); 

    你设置小提琴的方式也有问题。 你有name="date_hinfahrt" ,但在你的rules:选项中你使用了datefuture 。 此外, formtools.js不能与type="date"输入一起使用,因此它会清空该字段,导致它总是抱怨该字段是必需的; 我把它改成了type="text"

    小提琴

    需要了解更多jQuery教程分享jqueryvalidation将来的日期addMethod();,都可以关注jQuery技术分享栏目—计算机技术网(www.ctvol.com)!

      以上就是jQuery教程分享jqueryvalidation将来的日期addMethod();相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/981083.html

      (0)
      上一篇 2021年12月12日
      下一篇 2021年12月12日

      精彩推荐