[英]JQuery attr not setting max value but setting min for html input tag
I am working with some JQuery/Javascript and HTML tags. 我正在使用一些JQuery / Javascript和HTML标记。 I have a javascript document that sets the max/min values of an input tag in HTML5.
我有一个JavaScript文档,用于设置HTML5中输入标签的最大/最小值。 I am able to set my min value just fine for both of my tags, but the max value is not being set.
我可以为两个标签都设置最小值,但是没有设置最大值。 Does anyone see anything obivous I may be missing?
有人看到我可能会想念的东西吗? I'm just a little confused as to why the min is being set fine but the max is not.
我对为什么最小值设置得很好但是最大值没有设置感到困惑。 Thanks for the help.
谢谢您的帮助。
date.html date.html
Start Date (mm/yyyy): <input type="date" id="start_date" min="" max="">
End Date (mm/yyyy): <input type="date" id="end_date" min="" max=""/>
date.js date.js
//Last Valid/Year = 2014-06-01
//First Month/Year = 2012-11-01
//Max does not work even if I hard code it.
jQuery('#start_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + FirstMonth.toString() + "-" + "01"});
jQuery('#end_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + FirstMonth.toString() + "-" + "01" });
Oh my gosh, a really easy fix that took me literally all day. 哦,天哪,一个非常简单的修复程序使我整整一天都处于工作状态。 My last Valid year was 2014-6-30.
我的上一个有效年份是2014-6-30。 But the max needs to be read in as a yyyy/mm/dd format.
但是最大值需要以yyyy / mm / dd格式读取。 The fix was to add a 0 before the month if it is not october, december or november and to make sure that the day you are picking is a valid day in the month.
解决方法是,如果不是10月,12月或11月,则在该月之前添加0,并确保您选择的日期是该月中的有效日期。 IE, I was reading in 2014-6-31, and there are not 31 days in June.
IE,我在2014年6月31日看书,六月没有31天。 So the final string needed to be read in as 2014-06-30 instead of 2014-6-31
因此,最终的字符串需要读为2014-06-30而不是2014-6-31
jQuery('#end_date').attr({
"min": v.FirstYear.toString() + "-" + v.FirstMonth.toString() + "-" + "01",
"max": v.LastYear.toString() + "-" + "0" + v.LastMonth.toString() + "-" + "30",
"value": v.LastYear.toString() + "-" + "0" + v.LastMonth.toString() + "-" + "01"
});
use Firstmonth
instead of FirstMonth
"unknown variable used.this is problem." 使用
Firstmonth
代替FirstMonth
“使用了未知变量。这是问题。”
jQuery('#start_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + Firstmonth.toString() + "-" + "01"});
jQuery('#end_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + Firstmonth.toString() + "-" + "01" });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.