日期:2014-05-16  浏览次数:20486 次

jqueryUI关于子函数里的加载问题.
有这样一段代码 


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 (){
})里面的内容是我想在网页加载完成后就加载的. 上面的代码是一个函数的子函数模块,在网页加载完成后就成功加载了.
我现