0

我有 HTML5 代码:选择项目:

和后面的代码:

function fillItemsList(jsonResponse){
    var data = jsonResponse.invocationResult;
    var itemsString  = data.commodities.toString();
    itemsList = itemsString.split(",");
    $('#selectItem').empty();
    var options = "";
    for (var i = 0; i < itemsList.length; i++) {
        WL.Logger.debug(itemsList[i]);
         options += '<option value= "' + itemsList[i] + '">' + itemsList[i] + '</option>';

    }
    $('#selectItem').html(options);
    busyIndicator.hide();
    //$('#selectItem').Attributes.Add("onChange", "return itemSelectionChange();");
}
function itemSelectionChange(){
    WL.Logger.debug("Selected item changed");
    var index = $('#itemsList').prop("selectedIndex");
    var selectedItem = itemsList[index];
    getDeals(selectedItem);

}

我正在使用 IBM Worklight 创建一个 Web 应用程序并使用此代码。选择下拉列表获取所有值,但更改选择时不会调用该函数。

4

1 回答 1

1

取决于您使用的 jQuery 版本,但行:

//$('#selectItem').Attributes.Add("onChange", "return itemSelectionChange();")

应该是这样的:

$('#selectItem').bind('change', function(){return itemSelectionChange();});
于 2012-10-18T07:55:26.897 回答