0

我正在使用 JavaScript 和 Html 创建一个 iPad 应用程序。用于页面设计的 HTML 和用于功能的 JavaScript。我有一个使用 Html 创建的 displayBox,我想使用 javascript 用一系列国家/地区填充它。

它当前仅将数组中的第一项添加到 displayBox 但是当我使用 firefox 调试应用程序时出现以下错误

编辑:

我得到了它的工作,我不得不脱掉它的末端

前:

$('#countrySelection').append('<option value="' + this.id + '">' + this.name + '</option>').selectmenu('refresh');

$('#countrySelection').append('<option value="' + this.id + '">' + this.name + '</option>');

.selectmenu('refresh') 导致错误

4

1 回答 1

0

我做了一些更新,比如添加 $(document).ready() 处理程序等。

var arrayOfCountries = [{"name":"USA","id":1,"active":"Y"},{"name":"CANADA","id":2,"active":"Y"},{"name":"AALAND ISLANDS","id":270,"active":"Y"},{"name":"AFGHANISTAN","id":236,"active":"Y"},{"name":"ALBANIA","id":109,"active":"Y"},{"name":"ALGERIA","id":17,"active":"Y"},{"name":"AMERICAN SAMOA","id":307,"active":"Y"},{"name":"AMMAN","id":111,"active":"Y"},{"name":"ANDORRA","id":112,"active":"Y"},{"name":"ANGOLA","id":54,"active":"Y"},{"name":"ANGUILLA","id":22,"active":"Y"},{"name":"ANTARTICA","id":308,"active":"Y"},{"name":"ANTIGUA","id":113,"active":"Y"}];

$(document).ready(function(){

if ( $('#countrySelection').find('option').length == 0 ){

    $.loadingMessage = "Retrieving Countries";
    $.showPageLoadingMsg();

        $.each(arrayOfCountries, function() {
            $('#countrySelection').append('<option value="' + this.id + '">' + this.name + '</option>');//.selectmenu('refresh');
        });
       $.mobile.hidePageLoadingMsg();
}

});​
于 2012-05-09T08:59:13.483 回答