在Internet Explorer中使用.append()刷新列表框的内容 [英] refreshing the contents of a listbox with .append() in Internet Explorer

查看:98
本文介绍了在Internet Explorer中使用.append()刷新列表框的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With jQuery on Firefox and Chrome I can just dynamically change the data in a listbox with $().append() statements or whichever way I need to. The same code doesn't work with IE. The listbox (<select></select>) is just static and none of the elements are added/removed/changed.

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

I heard IE can be a bit "different" in handling listbox (<select></select>) re-rendering.

如何让jQuery的 .append()使用Internet Explorer?

How can you make jQuery's .append() work with Internet Explorer?

推荐答案

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

What are you trying to do. If you just want to load data using ajax and wanted to manipulate your <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');

然后你只需要用你所有的选项形成一个字符串中的元素,然后使用 .html()

You then just need to form a string with all your option elements in it, then load it unto the select box using .html()

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

if you want a more elegant way to manipulate your select box . You could give this a try. http://www.texotela.co.uk/code/jquery/select/

这篇关于在Internet Explorer中使用.append()刷新列表框的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆