使用Firefox和Chrome上的jQuery,我可以使用$().append()
语句或我需要的任何方式动态更改列表框中的数据。相同的代码不适用于IE。列表框(<select></select>
)只是静态的,没有添加/删除/更改任何元素。
我听说IE在处理列表框(<select></select>
)重新渲染时可能有点“不同”。
如何让jQuery的.append()
与Internet Explorer协同工作?
答案 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/