我尝试从json中的select populate为div“sel_user”加载用户的值。
嗨,大家好我试图从div“sel_user”中加载JSON文件中的数据。当我从populate中选择一个选项时,加载此数据也会从此JSON中选择create。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-1.12.0.min.js" type="text/javascript"></script>
<!--funcion para cargar el select box desde el json-->
<script type="text/javascript">
$(function() {
$.getJSON('checkin.php', function(data) {
var items = '';
var len = data.length;
var name = data[0]['name'];
var tiempo = data[0]['tiempo'];
$.each(data, function(name, value) {
items += "<option value='" + value.id + "'>" + value.name + "</option>";
});
$("#clients").html(items);
$("#sel_user").append("<div>" + name + "</div>");
$("#sel_user").append("<div>" + tiempo + "</div>");
$("#sel_user").append("<div>" + name + "</div>");
});
});
</script>
</head>
<body>
<select id="clients">
<option value="0">-- choose user --</option>
</select>
<div>-- info user --</div>
<div id="sel_user"></div>
</body>
</html>
我的JSON是
"usuarios": [
{
"codigo": "U001",
"name": "EDWAR TOBAR",
"cargo": "",`enter code here`
"telefono": "",
"email": "",
"telefono1": "3137532371",
"abonados": 8,
"tiempo": "2017-04-28T22:03:18.000Z",
"evento": "",
"devento": ""
},
{
"codigo": "U002",
"name": "JHON HENRY CARVAJAL",
"cargo": "",
"telefono": "",
"email": "",
"telefono1": "3136706365",
"abonados": 8,
"tiempo": "2017-04-28T22:03:18.000Z",
"evento": "",
"devento": ""
},
{
"codigo": "U006",
"name": "CLAVE DE COACCION",
"cargo": "",
"telefono": "",
"email": "",
"telefono1": "",
"abonados": 8,
"tiempo": "2017-04-28T22:03:18.000Z",
"evento": "",
"devento": ""
},
{
"codigo": "U003",
"name": "JAVIER QUI ONEZ",
"cargo": "",
"telefono": "",
"email": "",
"telefono1": "3177364180",
"abonados": 8,
"tiempo": "2017-04-28T22:03:38.000Z",
"evento": "",
"devento": ""
}
]
}
select id =“clients”工作正常。在jquery函数时为用户收取我的JSON费用。但是,当我选择一个用户时,用户的数据会在div id =“sel_user”中收费。求你帮帮我。