1、javascript里求如何调用局部变量;alert放在函数里可以显示,但是放在外面显示是undefined。2、代码如下:<html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> body, html,#allmap {width: 90%;height: 90%;overflow: hidden;margin:0;font-family:"微软雅黑";} </style> <script src="http://search.dangdang.com/Standard/Search/Extend/hosts/js/jquery.js"></script> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nCRvMdrWkhF3kg0RsTdUvku6"></script> <title>出行</title></head><body><div id="allmap"></div></body></html><script type="text/javascript"> var map = new BMap.Map("allmap"); map.centerAndZoom(new BMap.Point(118.799154,32.066449), 12); map.enableScrollWheelZoom(); var ttime; var tdistance; var s; var p1 = new BMap.Point(118.790662,32.057327); var p2 = new BMap.Point(118.812128,32.046538); var searchComplete = function (results){ if (transits.getStatus() != BMAP_STATUS_SUCCESS){ return ; } var plan = results.getPlan(0); this.ttime = plan.getDuration(true); //获取时间 tdistance = plan.getDistance(true); //获取距离 }; var transits = new BMap.TransitRoute(map, {renderOptions: {map: map}, onSearchComplete: searchComplete}); transits.search(p1, p2); alert(ttime)</script></html>
添加回答
举报
0/150
提交
取消