いくつかの日付を持つ選択要素がありますが、日付ピッカーから日付を選択できるようにしたいので、選択フィールドの横にカレンダー アイコンを表示する次のコードがあります。
<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 は、select html 要素に新しいオプションを追加するべきではありませんか? 何が悪いのかわかりませんか?
ありがとう。
更新 1:
onSelect: function(dateText, inst) {
var opt = $('<option />').attr('value', dateText).text(dateText);
$('select[name=birthday]').append(opt);
}
完璧に動作します。新しいオプションを選択したことをマークする必要があることだけを述べているので、次のように編集してください。$('<option selected/>')