gpt4 book ai didi

jquery - 使用 jquery 将状态 json 数据放入下拉列表中选择

转载 作者:行者123 更新时间:2023-12-01 03:01:09 26 4
gpt4 key购买 nike

这是返回的 json 数据:

({"Data":{"Alabama":"AL","Alaska":"AK","Arizona":"AZ","Arkansas":"AR","California":"CA","Colorado":"CO","Connecticutt":"CT","Delaware":"DE","Florida":"FL","Georgia":"GA","Hawaii":"HI","Idaho":"ID","Illinois":"IL","Indiana":"IN","Iowa":"IA","Kansas":"KS","Kentucky":"KY","Louisiana":"LA","Maine":"ME","Massachusetts":"MA","Michigan":"MI"}})

我需要将其放入下拉选择中。

$.getJSON(url + 'GetStateList?jsoncallback=?',
function (json) {
if (!jQuery.isEmptyObject(json.Data)) {
//need to write logic
}
});

谁能帮我解决这个问题吗?

最佳答案

var data = 'jsonstring', i, select = $('select');

for(i in data){

select.append($('<option value="' + data[i][1] + '">' + data[i][0] + '</option>'));

}

关于jquery - 使用 jquery 将状态 json 数据放入下拉列表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9331456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com