JQuery Datepicker - 添加年份(JQuery Datepicker - Add Years)
我已将JQuery Datepicker控件添加到我的一个ASP.Net页面中。 该页面允许用户添加有关设备的详细信息。
他们还可以使用Datepicker选择他们购买设备的日期,然后从下拉列表中选择设备随附的保修长度(即1,2,3,4,5岁等)。 根据他们选择的保修期,我需要JQuery代码来计算保修期到期的设备,即,如果购买21/02/2011,3年保修,则保修到期日为21/02/2014。
我看过这个网站上的其他Datepicker示例,但似乎都没有显示如何添加年份到日期,而只是如何添加天。
到目前为止这是我的代码
$('#equipment_purchaseDate').datepicker({ dateFormat: 'dd/mm/yy', onSelect: function (dateStr) { var d = $.datepicker.parseDate('dd/mm/yy', dateStr); d.setDate(d.getDate() + ($('#equipment_warrantyLength').val() * 365)); //multiple warranty length by 365 to get years, then add to startDate $('#equipment_warrentyExpires').datepicker('setDate', d); } });
但是这似乎没有正常工作。
任何反馈都将非常感激。
谢谢。
I have added the JQuery Datepicker control to one of my ASP.Net pages. The page allows a user to add details about a piece of equipment.
They can also select the date they bought the equipment using the Datepicker, then from a drop down list, select the warranty length (ie, 1,2,3,4,5 years etc) that comes with the equipment. Based on the warranty length they have selected, I need JQuery code to work out the date the warranty will expire for the Equipment, ie, if bought 21/02/2011, 3 year warrenty, then warranty expires 21/02/2014.
I have looked at the other Datepicker examples on this site, but none seem to show how to add years to a date, rather just how to add days.
This is my code so far
$('#equipment_purchaseDate').datepicker({ dateFormat: 'dd/mm/yy', onSelect: function (dateStr) { var d = $.datepicker.parseDate('dd/mm/yy', dateStr); d.setDate(d.getDate() + ($('#equipment_warrantyLength').val() * 365)); //multiple warranty length by 365 to get years, then add to startDate $('#equipment_warrentyExpires').datepicker('setDate', d); } });
However this doesn't seem to be working correctly.
Any feedback would be much appreciated.
Thanks.
原文:https://stackoverflow.com/questions/5067765
最满意答案
->addValidator('StringLength', false, array(2, $metaData['first_name']['LENGTH']));
如果长度属于[2,x],其中x是
$metaData[...][...]
值,则添加一个只考虑字符串有效的验证器。 (在内部,表单将创建并配置Zend_Validate_StringLength
实例。)
->addValidator('StringLength', false, array(2, $metaData['first_name']['LENGTH']));
Will add a validator that will only consider a string valid if it's length falls in [2, x] where x is the
$metaData[...][...]
value. (Internally, the form will create and configure aZend_Validate_StringLength
instance.)
相关问答
更多-
你忘了给装饰者添加错误了。 $this->setDecorators(array( // add this line 'Errors', 'FormElements', array('HtmlTag', array('tag' => 'table', 'class' => 'signuptable')), 'Form' )); You forgot to add errors to the decorator. $this->setDecorators(arr ...
-
我从来没有使用ini配置来创建我的表单,但是这绝对是这样的: validators.between.validator = "Between" validators.between.options.min = 8 validators.between.options.max = 60 validators.between.options.inclusive = true 查看Zend Validator Between文档中的选项详细信息。 I have never used the ini config ...
-
要将验证器选项注入到您的构造函数方法中,您应该在module.config.php文件中注册您的验证器: array( 'factories' => array( ImageValidator:: ...
-
为什么这个Zend_Form NotEmpty验证器会给我一个错误信息?(Why does this Zend_Form NotEmpty validator give me an error message?)[2022-11-03]
好吧,所以我没有真正得到我的问题的答案,但是我已经意识到setRequired()验证器是一个复杂的小动物,可能不是Zend团队最自豪的时刻。 所以,我没有找到上面问题的答案,而是找到了一个非常好用的setRequired方法。 这里是: $this->addElement('text', 'orgName'); $this->orgName ->setLabel('Name') ->addFilter('StringTrim') ... -
文件上载表单的Zend验证程序大小 - Zend Framework 2.3(Zend Validator Size for File Uploading Form - Zend Framework 2.3)[2024-03-09]
如果您想将8M作为最大限制处理,则upload_max_filesize和post_max_size应大于8M,否则您将收到这些警告。 如果您对这些警告感到恼火,这是一种避免它们的方法: 如何防止警告:POST内容长度和内存大小 your upload_max_filesize & post_max_size should be bigger than 8M if you want to handle 8M as a max limit, or else you will receive those war ... -
AFAIK没有像NotIdentical这样的东西。 你是否以这种方式尝试过自己的验证器?: class My_Validate_NotIdentical extends Zend_Validate_Identical { public function isValid($value) { return !parent::isValid($value); } } 它只是最简单的解决方案 - 您还应该更改验证消息等。 AFAIK there is not someth ...
-
有Zend_Validate_Identical 。 There's Zend_Validate_Identical.
-
您可以使用Zend_Filter LocalizedToNormalized过滤器来根据用户的区域设置将您的本地化价格标准化。 典型的价格要素就像这样: $price = new Zend_Form_Element_Text('price'); $price->setLabel('Price:') ->setRequired(true) ->setAttribs(array('required name' => 'price', 'maxlength' => '12')) ...
-
->addValidator('StringLength', false, array(2, $metaData['first_name']['LENGTH'])); 如果长度属于[2,x],其中x是$metaData[...][...]值,则添加一个只考虑字符串有效的验证器。 (在内部,表单将创建并配置Zend_Validate_StringLength实例。) ->addValidator('StringLength', false, array(2, $metaData['first_name'][' ...
-
尝试 $validatorNotEmpty->setMessages(array('agreeRules')); 它将覆盖所有消息,但在IS_EMPTY情况下,它实际上是一条消息 你可以尝试另一种方法,按价值翻译 删除Zend_Validate_NotEmpty::IS_EMPTY => 'Поле не может быть пустым', $errors=array( //values 'Value is required and cannot be empty' = > 'My tra ...