jquery 中的小新。我正在使用 jquery 创建两个列表框。一个包含日期,另一个包含月份。两者都在我的 html 页面中的不同位置使用。所以我试着把它放在一个函数中
但这不起作用。http://jsfiddle.net/mVR6g/4/
<div class="drop">
<div style="float:left;">Date of Birth : </div>
<div class="current"><input type="text" name="Mem_DOB" class="memdate1"/></div>
<div class="alldate1"></div> <div class="allmonth1"></div>
</div>
<div class="drop">
<div style="float:left;">Wedding Anniversery : </div>
<div class="current"><input type="text" name="Mem_WAnn" class="memdate2"/></div>
<div class="alldate2"></div> <div class="allmonth2"></div>
</div>
$(document).ready(function () {
$('.memdate1').click(function () {
var date = $('.alldate1').attr('id');
alert(date);
var month = $('allmonth1').attr('id');
Genratecalender(date, month);
});
$('.memdate2').click(function () {
var date = $('.alldate1').attr('id');
alert(date);
var month = $('allmonth2').attr('id');
Genratecalender(date, month);
});
function Genratecalender(date,month) {
var arr = []
for (var i = 1; i < 32; i++) {
arr.push({ val: i, text: i })
}
var sel = $('<select>');
$(arr).each(function () {
sel.append($("<option>").attr('value', this.val)
.text(this.text));
});
$('.div'+ date).html(sel);
$('.div'+ date).show();
//month list
var arr = [
{ val: 'January', text: 'January' },
{ val: 'February', text: 'February' },
{ val: 'March', text: 'March' },
{ val: 'April', text: 'April' },
{ val: 'May', text: 'May' },
{ val: 'June', text: 'June' },
{ val: 'July', text: 'July' },
{ val: 'August', text: 'August' },
{ val: 'September', text: 'September' },
{ val: 'October', text: 'October' },
{ val: 'November', text: 'November' },
{ val: 'December', text: 'December' },
];
var sel = $('<select>');
$(arr).each(function () {
sel.append($("<option>").attr('value', this.val)
.text(this.text));
});
$('.div' + month).html(sel);
$('.div' + month).show();
//$('.memdate').hide();$("div#" + name).
}
});