日期:2014-05-16 浏览次数:20809 次
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="selectdata.js"></script>
<script type="text/javascript">
$(document).ready(function(){
showselect($("select"));
});
</script>
</head>
<body>
<div id="select" name="select "class="select"></div>
<input type="submit" class="button" value="echo" />
</body>
</html>
function showselect(htmlContainer){
$.ajax({
url:"selectdata.php",
type:"post",
dataType:"json",
success:function(data){
var select = document.createElement("select");
for(var name in data.sex){
var option = document.createElement("option");
option.name = name;
option.innerHTML = name;
option.value = data.sex[name];
select.appendChild(option)
}
document.getElementsByTagName("body")[0].appendChild(select)
}
});
}
<?php
include ("JSON.php");
$json = new Services_JSON();
$arr = array("sex select"=>"","man"=>"male","woman"=>"famale","other"=>"other");
$str = array("sex"=>$arr);
$json&nb