使用Jquery将值填充到来自JSON文件的下拉列表中 [英] Populate values to dropdown list from a JSON file using Jquery

查看:230
本文介绍了使用Jquery将值填充到来自JSON文件的下拉列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html下拉列表。在页面加载时,我必须使用Jquery从JSON.JS文件填充值。

I have a html dropdown list. On page load, I have to populate the values from a JSON.JS file using Jquery.

JSON文件包含:

The JSON file contains:

var accounts = ["WHDH","TF"];


推荐答案

在添加json.js之后:

After the json.js has been added:

$(document).ready(function() {
    $('#myDropdown').empty(); // empty the dropdown (if necessarry)
    $(accounts).each(function(iIndex, sElement) {
        $('#myDropdown').append('<option>' + sElement + '</option>');
    });
});

另请参阅这个例子

这篇关于使用Jquery将值填充到来自JSON文件的下拉列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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