老师请检查
来源:4-7 自由编程
小丁同学ddd
2020-03-19 16:41:45
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15
&key=7e9250711428c2f6c60ce39d26797daa&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
<style type="text/css">
*{
padding: 0;
margin: 0;
list-style: none;
}
#container {
width:100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.clickNode{
width: 300px;
height: 500px;
border: 1px solid pink;
position: absolute;
box-shadow: 0 5px 5px deepskyblue;
top: 70px;
right: 20px;
z-index: 999;
background-color: pink;
}
#node{
cursor: pointer;
}
.searchNode{
width: 300px;
height: 30px;
position: absolute;
background-color: white;
z-index: 999;
top: 10px;
right: 20px;
}
</style>
</head>
<body>
<div class="searchNode">
<input type="text" id="searchText" />
<button id="btn">搜索</button>
</div>
<div class="clickNode" id="clickNode">
<!--<input type="text" />
<button id="btn">确定</button>-->
</div>
<div id="container"></div>
<script type="text/javascript">
var map = new AMap.Map('container',{
zoom:11, //初始的级别
center:[116.379391,39.861536] //初始化地图的中心店
});
AMap.service(['AMap.PlaceSearch'],function(){
btn.onclick = function(){
new AMap.PlaceSearch({
pageIndex:1, //默认在第一页
pageSize:5, //一页最多显示5条
city:'010', //放区号就可以
map:map, //展示在哪个地图里
panel:'clickNode' //放在哪里
}).search(searchText.value);
}
var searchNode = new AMap.Autocomplete({
input:'searchText',
});
var placeSearch = new AMap.PlaceSearch({
map:map
});
AMap.event.addListener(searchNode,'select',function(e){
placeSearch.search(e.poi.name)
})
});
//key后+
</script>
</body>
</html>
1回答
同学你好,如下所示,点击下拉框的内容,无法显示对应的搜索结果。

原因:只在”搜索“按钮的点击事件中设置了显示搜索结果。
建议:在placeSearch中同样设置搜索结果的显示

建议优化:去掉clickNode盒子的高度,让其由内容撑开高度,同时去掉背景颜色等属性,效果实现会更好。

如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
相似问题