处理表单刷新的jQuery Birthday Picker [英] jQuery Birthday Picker dealing with form refresh

查看:133
本文介绍了处理表单刷新的jQuery Birthday Picker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里演示:
http://abecoffman.com/stuff/birthdaypicker/



问题我处理的是表单验证。我的表单验证重定向回到同一个页面,我会丢失所选的日期。



有没有办法为日期选择器的javascript添加一个选项:
http://abecoffman.com/stuff/birthdaypicker/bday-picker。 js



,以便我可以设置默认选择的日期。该配置可以工作到:

  $(#picker1)。birthdaypicker({
selectedDay:1 ;
selectedMonth:28;
selectedYear:2011;
});

这将选择日期设置为2011年1月28日。

解决方案

不修改插件可以使用JQuery设置值,插件生成的标记如下所示:

 < fieldset class ='birthday-选择器'> 
< select class ='birth-year'name ='birth [year]'>< / select>
< select class ='birth-month'name ='出生[月]'>< / select>
< select class ='birth-day'name ='birth [day]'>< / select>
< / fieldset>

所以你的JQuery只需要保持这些元素和设置他们的价值,你想确定哟您将设置选择列表中存在的值。

  $('select.birth-year')。val 'my_year'); // 1980 
$('select.birth-month')。val('my_month'); // 1-12(不是Jan,这是文本)
$('select.birth-day')。val('my_day'); // 1-31(保持月份限制)

此代码必须在插件已被调用,否则标记将不会生成。


I'm using an excellent jquery plugin for Birthday Date picking for my web form.

Demo here: http://abecoffman.com/stuff/birthdaypicker/

The problem I'm dealing with is on a form validation. My form validation redirect back to the same page and I'll lose the date that was picked.

Is there any way to add an option to the javascript of the date picker: http://abecoffman.com/stuff/birthdaypicker/bday-picker.js

so that I can set a "default selected date". The config can work to something like:

$("#picker1").birthdaypicker({
  chosenDay: 1;"
  chosenMonth: 28;"
  chosenYear: 2011;"
 });

This will set the "selected" date to January 28, 2011.

解决方案

Without modifying the plugin you could use JQuery to set the values. The markup that the plugin generates looks like this:

<fieldset class='birthday-picker'>
    <select class='birth-year' name='birth[year]'></select>
    <select class='birth-month' name='birth[month]'></select>
    <select class='birth-day' name='birth[day]'></select>
</fieldset>

So your JQuery would simply have to get a hold on those elements and set their value. You'd want to make sure you're setting a value that exists in the select list.

$('select.birth-year').val('my_year');      // 1980
$('select.birth-month').val('my_month');    // 1-12 (not "Jan" which is the text)
$('select.birth-day').val('my_day');        // 1-31 (keep month limitation in mind)

This code would have to be called after the plugin has been called, otherwise the markup won't have been generated yet.

这篇关于处理表单刷新的jQuery Birthday Picker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆