4
我有一個選擇元素與幾個日期,但我也想給datepicker選擇一個日期的可能性,所以我有以下代碼顯示日曆圖標旁邊選擇字段。'選擇'元素的jQuery ui.datepicker
<select name="birthday" >
<option value="${merge0.birthday}">${merge0.birthday}</option>
<option value="${merge1.birthday}">${merge1.birthday}</option>
</select>
<input type="hidden" id="bday_icon" />
然後,這是我的日期選擇器的腳本
$("#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);
}
});
不該功能ONSELECT,添加一個新的選項,選擇HTML元素?你不知道它是什麼問題嗎?
謝謝。
更新1:
onSelect: function(dateText, inst) {
var opt = $('<option />').attr('value', dateText).text(dateText);
$('select[name=birthday]').append(opt);
}
運行完美,只是此話,我需要標記爲選擇新的選項,只需編輯,如:$('<option selected/>')
非常感謝您根據我的需要完美地工作。 – framara 2010-01-21 09:59:38