私は、次のtest.json持っている:私の質問はどのように、あるJSONデータが入力されたドロップダウンリストから選択の詳細を取得するにはどうすればよいですか?
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<script src="jquery.js"></script>
</head>
<body>
<div>
<select id="countries"></select>
<br>
<textarea id="detailsbox" rows="4" cols="50">
</textarea>
</div>
</body>
<script type="text/JavaScript">
$(document).ready(function() {
var $select = $('#countries')
$.getJSON('test.json',function(translations){
$select.html('');
//iterate over the data and append a select option
$.each(translations.countries, function(key, val){
$select.append('<option id="' + val.countryCode + '">' + val.officialName + '</option>');
})
});
});
</script>
</html>
:
{"countries":[{"countryCode":"US","officialName":"UNITED STATES OF AMERICA","continent":"NORTH AMERICA","currentSeason":"WINTER"},{"countryCode":"AR","officialName":"ARGENTINA","continent":"SOUTH AMERICA","currentSeason":"SUMMER"}]}
そして、次のHTML/jQueryのJSONデータからofficialName
値とドロップダウンを移入選択した国に基づいて他の従属データ(currentSeason、countryCode、大陸など)にアクセスし、そのデータでdetailsBox
テキストエリアを記入できますか?
ありがとうございます。
ありがとうございました – ITWorker
@ITWorkerがうれしいコーディングを手伝ってうれしいです:) – guradio