代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#recommend font{
font-size: 60px;
font-weight: bold;
}
#recommend{
margin-bottom: 10px;
}
#houseImg{
float: left;
}
#houseInformation{
height: 200px;
width: 660px;
float: left;
position: relative;
border-bottom: 1px solid gainsboro;
}
#houseInformation h1{
margin-top:0 ;
font-size: 50px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#houseInformation .housename{
font-size: 30px;
color: gray;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#price{
font-size: 40px;
color: orangered;
position: absolute;
bottom: -8px;
}
#houseImg img{
width: 300px;
height: 200px;
}
#houseMessage{
float: left;
margin-top: 8px;
width: 100%;
border: 0;
white-space: nowrap;
overflow: hidden;
}
</style>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="recommend">
<font>推荐</font>
</div>
<div id="houselist">
<div id="houseMessage">
</div>
</div>
</body>
</html>
<script type="text/javascript">
$.ajax({
type:"get",
url:"http://rap2api.taobao.org/app/mock/177073/houseList",
async:true,
success:function(result){
houselist = result['datalist']
console.log(houselist)
for (x=0;x<houselist.length;x++){
house = houselist[x]
addressNode = $('<font class="housename">'+house['address']+'|</font>')
areaNode = $('<font class="housename">'+house['area']+'|</font>')
console.log(house['img'])
imgNode = $('<img src='+house['image']+'/>')
nameNode = $('<font class="housename">'+house['name']+'|</font>')
priceNode = $('<font id="price">'+house['price']+'</font>')
titleNode = $('<h1>'+house['title']+'</h1>')
typeNode = $('<font class="housename">'+house['type']+'</font><br />')
houseMessageNode = $('<div id="houseMessage"></div>')
houseImgNode = $('<div id="houseImg"></div>')
houseInformationNode = $('<div id="houseInformation"></div>')
houselistNode = $('#houselist')
houseImgNode.append(imgNode)
houseMessageNode.append(houseImgNode)
houseInformationNode.append(titleNode)
houseInformationNode.append(nameNode)
houseInformationNode.append(addressNode)
houseInformationNode.append(areaNode)
houseInformationNode.append(typeNode)
houseInformationNode.append(priceNode)
houseMessageNode.append(houseInformationNode)
houselistNode.append(houseMessageNode)
}
}
});
</script>
效果图: