首页 > 代码库 > javascript 之获取 百度地址参数方法
javascript 之获取 百度地址参数方法
原生态的JavaScript对DOM的操作 比jquery更方便,特别是当没有id 或class 可以获取的时候,只有用tag名获取
HTML DOM Element 对象操作 http://www.w3school.com.cn/jsref/dom_obj_all.asp
百度开放平台 :http://lbsyun.baidu.com/index.php?title=open/library&qq-pf-to=pcqq.group
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> #container{ font-size:12px; margin:5px 0; } </style> <title> 城市列表显示示例</title> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script> <script type="text/javascript" src="http://api.map.baidu.com/library/CityList/1.4/src/CityList_min.js"></script> </head> <body> <div id="container"></div> <div style="width:520px;height:340px;border:1px solid gray" id="map_container"></div> <button type="button" onclick="displayDate()">show</button> <div id="demo"></div> </body> </html> <script type="text/javascript"> // 新创建地图 var map = new BMap.Map("map_container"); map.centerAndZoom(new BMap.Point(121.478125,31.229649), 12); var cityList = new BMapLib.CityList({ container: ‘container‘, map: map }); cityList.getBusiness(‘中关村‘, function(json){ console.log(‘商圈‘); console.log(json); }); cityList.getSubAreaList(131, function(json){ console.log(‘城市列表‘); console.log(json); }); cityList.addEventListener(‘cityclick‘, function(e){ console.log(e); }); function displayDate(){ var areaindex = 16; var b = document.getElementsByTagName(‘select‘)[2].childNodes[areaindex]; var c = document.getElementsByTagName(‘select‘)[3].childNodes; var txt =‘‘; for (i=1; i<c.length; i++) { if(i<c.length-1){ txt +=‘(\‘‘+c[i].value +‘\‘‘+ ‘,‘ +‘\‘‘+c[i].text+‘\‘‘+‘,‘+‘\‘‘+b.value+‘\‘‘+‘),‘+‘<br>‘; }else{ txt +=‘(\‘‘+c[i].value +‘\‘‘+ ‘,‘ +‘\‘‘+c[i].text+‘\‘‘+‘,‘+‘\‘‘+b.value+‘\‘‘+‘)‘+‘<br>‘; } }; var x=document.getElementById("demo"); x.innerHTML=txt; } </script>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css"> #container{ font-size:12px; margin:5px 0; }</style><title>城市列表显示示例</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script><script type="text/javascript" src="http://api.map.baidu.com/library/CityList/1.4/src/CityList_min.js"></script>
</head><body><div id="container"></div><div style="width:520px;height:340px;border:1px solid gray" id="map_container"></div>
<button type="button" onclick="displayDate()">show</button>
<div id="demo"></div></body></html><script type="text/javascript">// 新创建地图var map = new BMap.Map("map_container");map.centerAndZoom(new BMap.Point(121.478125,31.229649), 12);
var cityList = new BMapLib.CityList({ container: ‘container‘, map: map});
cityList.getBusiness(‘中关村‘, function(json){ console.log(‘商圈‘); console.log(json);});
cityList.getSubAreaList(131, function(json){ console.log(‘城市列表‘); console.log(json); });
cityList.addEventListener(‘cityclick‘, function(e){ console.log(e);});
function displayDate(){
var areaindex = 16;
var b = document.getElementsByTagName(‘select‘)[2].childNodes[areaindex];
var c = document.getElementsByTagName(‘select‘)[3].childNodes;
var txt =‘‘;
for (i=1; i<c.length; i++) { if(i<c.length-1){ txt +=‘(\‘‘+c[i].value +‘\‘‘+ ‘,‘ +‘\‘‘+c[i].text+‘\‘‘+‘,‘+‘\‘‘+b.value+‘\‘‘+‘),‘+‘<br>‘; }else{
txt +=‘(\‘‘+c[i].value +‘\‘‘+ ‘,‘ +‘\‘‘+c[i].text+‘\‘‘+‘,‘+‘\‘‘+b.value+‘\‘‘+‘)‘+‘<br>‘; } }; var x=document.getElementById("demo"); x.innerHTML=txt;
}
</script>
javascript 之获取 百度地址参数方法