【发布时间】:2021-03-25 03:05:57
【问题描述】:
我正在尝试显示数组中的数据。我从这个数组中获取了国家,但我需要在从下拉选项中选择后显示数据。
我需要将“making_calls”值放入 .price-call p 中,将“sending_texts”放入 .price-text p 中。
这是代码
array =[
{
"name": "Afghanistan",
"dial_code": "+93",
"code": "AF",
"making_calls": "€0.30",
"sending_texts": "€0.10",
"call_setup": "€0.15"
},
{
"name": "Albania",
"dial_code": "+355",
"code": "AL",
"making_calls": "€0.6",
"sending_texts": "€0.10",
"call_setup": "€0.15"
},
{
"name": "Algeria",
"dial_code": "+213",
"code": "DZ",
"making_calls": "€1.20",
"sending_texts": "€0.10",
"call_setup": "€0.15"
}
];
$.each(array, function (i, p) {
$('#selectCountry').append($('<option></option>').val(p.code).html(p.name + ' ' + '(' + p.dial_code+ ')' ));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="" id="selectCountry">
<option selected disabled>Country</option>
</select>
<div class="calls">
<p>Making Calls</p>
<p class="price-call">0.30$</p>
</div>
<div class="texts">
<p>Sending Texts</p>
<p class="price-text">0.15$</p>
</div>
【问题讨论】:
-
你会用 ReactJS 吗?