在Internet Explorer中使用.append()刷新列表框的内容

时间:2011-01-05 21:24:07

标签: jquery internet-explorer select

使用Firefox和Chrome上的jQuery,我可以使用$().append()语句或我需要的任何方式动态更改列表框中的数据。相同的代码不适用于IE。列表框(<select></select>)只是静态的,没有添加/删除/更改任何元素。

我听说IE在处理列表框(<select></select>)重新渲染时可能有点“不同”。

如何让jQuery的.append()与Internet Explorer协同工作?

1 个答案:

答案 0 :(得分:0)

你想做什么?如果您只想使用ajax加载数据并想要操纵<select></select>

var listBox = $("#CountyList");
$.post("/County/List/" + stateId, null, function (data) {
    var items = "<option value='0'>Select County</option>";
    $.each(data, function (i, c) {
        items += "<option value='" + c.Value + "'>" + c.Text + "</option>";
    });

    listBox.html(items);
}, 'json');

然后,您只需要在其中添加包含所有option元素的字符串,然后使用select

将其加载到.html()框中

如果您想要更优雅的方式来操纵select框。你可以尝试一下。 http://www.texotela.co.uk/code/jquery/select/