我想复制从json获取的li元素

时间:2018-07-09 09:56:05

标签: javascript json

myInput = "I like the colors blue and red."

def check_color(var):

    c_map = {'blue': 1, 'red': 2}

    L = []
    for colour, num in c_map.items():
        if colour in var:
            L.append(num)

    return L

print(check_color(myInput))

[1, 2]

1 个答案:

答案 0 :(得分:-1)

Sathish Thangaraj所述,请使用.append()方法:


//http://www.json-generator.com/api/json/get/cpPsULBvKG?indent=2

$.getJSON("https://www.json-generator.com/api/json/get/cpPsULBvKG?indent=2", function(data) {
  $.each(data, (i, el) => {
    $('#json_data').append(`<li>Value: ${el.value} | Key: ${el.key}</li>`);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="json_data">

</ul>