更新通过jQuery AJAX的选择框的选项? [英] Updating select box options via jQuery AJAX?

查看:86
本文介绍了更新通过jQuery AJAX的选择框的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些类型的插件来做到这一点?该服务器将返回JSON内容包含选项标签和值。

Is there some type of plugin to do this? The server will return JSON content containing the option labels and values.

我可以手动做到这一点,我只是想看看是否有更简单的方法。

I can do this manually, I just wanted to see if there was an easier way.

推荐答案

循环通过JSON和做每个文/值对(工程跨浏览器很好):

Loop through the json and do this on each text/value pair (works cross-browser nicely):

var opt = document.createElement('option');
opt.value = "someValue";
opt.appendChild(document.createTextNode("someText"));
$('#mySelect').append(opt);

这篇关于更新通过jQuery AJAX的选择框的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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