0

我有一个选择选项框html

<select name="selectDay" id="selectDay" data-mini="true" style="float: left;"></select>

在我使用 jQuery.append方法附加一些选项后,这些选项不会出现。

function showbroadcastsDropDown() {
for (i = 0; i < dateArray.length; i ++ ) {

    // variables
    var month = dateArray[i].getMonth() + 1;
    var year = dateArray[i].getYear();
    year += 1900;

    //dateArray[i].getDate() + "-" + month + "-" + year

    if (i == 0) {
        console.log("0");
        $("#sendungen select[name='selectDay']").append('<option value="today"' + (actuallyDate == dateArray[i].getDate() ? ' selected=true' : '') + '>today</option>');        
    } else if (i == 1) {
        console.log("1");
        $("#sendungen select[name='selectDay']").append('<option value="tomorrow">tomorrow</option>');          
    } else {
        console.log("else");
        $("#sendungen select[name='selectDay']").append('<option value="">asdasdasd</option>');     
    }

    console.log(dateArray[i].getDate() + "-" + month + "-" + year);
}
$("#sendungen select[name='selectDay']").selectmenu("refresh"); 

不要问dateArrayvar。

提前致谢!

4

4 回答 4

0

尝试:

 $("#selectDay").
         .append($("<option></option>")
         .attr("value",key)
         .text(value)); 
于 2013-07-30T09:59:42.063 回答
0

尝试

$("#sendungen select[name='selectDay']").selectmenu("refresh", true); // force rebuild
于 2013-07-30T10:11:23.613 回答
0

最后 :)

for (i = 0; i < dateArray.length; i ++ ) {
    var month = dateArray[i].getMonth() + 1;
    if (month == 13) month = 1;
    var year = dateArray[i].getYear();
    year += 1900;

    if (i == 0) {
        $("#" + site + " select[name='selectDay']").append("<option value=\"" + dateArray[i].getDate() + "-" + month + "-" + year + "\" " + (actuallyDate == dateArray[i] ? "selected='true'" : "") + ">" + showbroadcastsDropDown_localize.today + "</option>");
    } else if (i == 1) {
        $("#" + site + " select[name='selectDay']").append("<option value=\"" + dateArray[i].getDate() + "-" + month + "-" + year + "\" " + (actuallyDate == dateArray[i] ? "selected='true'" : "") + ">" + showbroadcastsDropDown_localize.tomorrow + "</option>");        
    } else {
        $("#" + site + " select[name='selectDay']").append("<option value=\"" + dateArray[i].getDate() + "-" + month + "-" + year + "\" " + (actuallyDate == dateArray[i] ? "selected='true'" : "") + ">" + dateArray[i].getDate() + "-" + month + "</option>");        
    }
}

$("#" + site + " select[name='selectDay']").selectmenu("refresh");  
于 2013-08-01T07:03:07.090 回答
0

试试下面的代码:

<select name="selectDay" id="selectDay" data-mini="true" style="float: left;"></select>
<input type="button" id="btnClick" />

jQuery

$(document).ready(function(){    
$("#btnClick").click(function(){
$("#selectDay").append(new Option("option text", "value"));
});
});
于 2013-07-30T10:20:58.567 回答