有这样一段代码
- HTML code
addVtHeader: function (div, data, cellHeight) { var headerDiv = jQuery("<div>", { "class": "ganttview-vtheader" }).append("<span class='divspan'>项目名称</span><span class='divspan1'>开始日期</span><span class='divspan1'>结束日期</span>"); for (var i = 0; i < data.length; i++) { var itemDiv = jQuery("<div>", { "class": "ganttview-vtheader-item" }); itemDiv.append(jQuery("<div>", { "class": "ganttview-vtheader-item-name", "css": { "height": (data[i].series.length * cellHeight) + "px" } }).append(data[i].name)); var seriesDiv = jQuery("<div>", { "class": "ganttview-vtheader-series" }); for (var j = 0; j < data[i].series.length; j++) { var startname="starttime"+j; var endname="endtime"+j; var starttimeval=(data[i].series[j].start.getYear()+1)+"-"+(data[i].series[j].start.getMonth()+1)+"-"+data[i].series[j].start.getDate(); var endtimeval=(data[i].series[j].start.getYear()+1)+"-"+(data[i].series[j].end.getMonth()+1)+"-"+data[i].series[j].end.getDate(); seriesDiv.append(jQuery("<div>", { "class": "ganttview-vtheader-series-name" }) //.append(data[i].series[j].name)); .append( "<input style='width:100px;' class='from' id='"+startname+"' value='"+starttimeval+"'/>" +"<input style='width:100px;' class='to' id='"+endname+"' value='"+endtimeval+"'/>" )); $(document).ready(function (){ $( "#"+startname+ ","+ "#"+endname ).datepicker({ showMonthAfterYear:true, changeYear:true, numberOfMonths: 1, dateFormat: "yy-mm-dd", onSelect: function( selectedDate ) { alert("1"); var option = this.id == start ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ); date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); }); } // value='"+(data[i].series[j].start.getMonth()+1)+"月"+data[i].series[j].start.getDate()+"日' // value='"+(data[i].series[j].end.getMonth()+1)+"月"+data[i].series[j].end.getDate()+"日' itemDiv.append(seriesDiv); headerDiv.append(itemDiv); } div.append(headerDiv); },
其中$(document).ready(function (){
})里面的内容是我想在网页加载完成后就加载的. 上面的代码是一个函数的子函数模块,在网页加载完成后就成功加载了.
我现在就想给这2个input绑个日历.但是怎么试都无法加载成功,希望有经验的朋友帮忙看看,这一块的逻辑我不太懂.欢迎高手介入.
千万不要告诉我把日历提取到主页面然后绑click事件执行.