'select'元素上的jQuery ui.datepicker [英] jQuery ui.datepicker on 'select' element
问题描述
我有一个选择元素与几个日期,但我也想给datepicker选择一个日期的可能性,所以我有下面的代码显示选择字段旁边的日历图标。
< select name =birthday>
< / select>
< input type =hiddenid =bday_icon/>
然后,这是我的datepicker脚本
<$ (
{
changeMonth:true,
changeYear:true,
showOn:'button')pre>
$(#bday_icon ,
buttonImage:'cal / images / calendar.gif',
buttonImageOnly:true,
onSelect:function(dateText,inst){
var field = document.getElementsByNameByName(生日);
var opt = document.createElement('option');
opt.text = dateText;
opt.value = dateText;
field.add(opt, null);
}
});
不应该使用onSelect函数,为select html元素添加一个新选项?你不知道它有什么不对吗?
谢谢。
更新1:
onSelect:function(dateText,inst){
var opt = $('< option />').attr('value ',dateText).text(dateText);
$('select [name = birthday]')。append(opt);
}
完美的作品,只有我需要标记为选中的新选项只需编辑如下: $('< option selected />')
除非它们是你的一些函数,否则我不太确定 .add()
和 getElementsByNameByName()
是。我似乎无法在jQuery api中找到 add
。
另外,在使用jQuery小部件时,我更喜欢使用jQuery选择器:
onSelect:function(dateText,inst){
var opt = $('< option />').attr('value',dateText).text(dateText);
$('select [name = birthday]')。append(opt);
}
适用于我。
I have a select element with a couple of dates but I also want to give the possibility of picking a date from the datepicker so I have the following code that displays a calendar icon next to the select field.
<select name="birthday" >
<option value="${merge0.birthday}">${merge0.birthday}</option>
<option value="${merge1.birthday}">${merge1.birthday}</option>
</select>
<input type="hidden" id="bday_icon" />
Then, this is my datepicker script
$("#bday_icon").datepicker(
{
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: 'cal/images/calendar.gif',
buttonImageOnly: true,
onSelect: function(dateText, inst) {
var field = document.getElementsByNameByName("birthday");
var opt = document.createElement('option');
opt.text = dateText;
opt.value = dateText;
field.add(opt, null);
}
});
Shouldn't the function onSelect, add a new option to the select html element? can't you see what it's wrong?
Thanks.
Update 1:
onSelect: function(dateText, inst) {
var opt = $('<option />').attr('value', dateText).text(dateText);
$('select[name=birthday]').append(opt);
}
Works perfect, only remark that I needed to mark as selected the new option so just edit like: $('<option selected/>')
Unless they're some of your functions, I'm not really sure what .add()
and getElementsByNameByName()
are. I can't seem to find add
in the jQuery api.
Also, when working with jQuery widgets, I prefer to use jQuery selectors:
onSelect: function(dateText, inst) {
var opt = $('<option />').attr('value', dateText).text(dateText);
$('select[name=birthday]').append(opt);
}
Works for me.
这篇关于'select'元素上的jQuery ui.datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!