如何使用silverlight项目中的多个参数调用javascript函数?

时间:2012-02-10 10:25:20

标签: javascript html silverlight invoke

我有一些麻烦,从html页面调用一个带有多个参数的javascript函数,这就是我正在做的事情:

wbNavigator.Navigate(new Uri("http://localhost:56433/route.html" ,UriKind.Absolute) );
object results= wbNavigator.InvokeScript("calculer", new string[] {"3.072526", "36.766942", "3.042526", "36.766942"});

但是在没有任何事情的情况下进行骚扰。我错过了什么? 那是我的javascript代码:

<script type="text/javascript">
       var directionsService = new google.maps.DirectionsService();
              var directionsDisplay = new google.maps.DirectionsRenderer();
              var myOptions = {
                  zoom: 7,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
              }
       function calcluer(lon_A, lat_A, lon_B, lat_B) {
           var map = new google.maps.Map(document.getElementById("map"), myOptions);
           directionsDisplay.setMap(map);
           var salle2 = new google.maps.LatLng(lat_A, lon_A);
           var salle3 = new google.maps.LatLng(lat_B, lon_B);
           var request = {
               origin: salle2,
               destination: salle3,
               travelMode: google.maps.DirectionsTravelMode.DRIVING
           };  
       directionsService.route(request, function (response, status) {
           if (status == google.maps.DirectionsStatus.OK) {
               // Display the distance:
               document.getElementById('distance').innerHTML +=
                response.routes[0].legs[0].distance.value + " meters";
               // Display the duration:
               document.getElementById('duration').innerHTML +=
                response.routes[0].legs[0].duration.value + " seconds";
               directionsDisplay.setDirections(response);
           }
       });
       }
       </script> 

1 个答案:

答案 0 :(得分:2)

只需使用: -

object results= wbNavigator.InvokeScript("calculer", "3.072526", "36.766942", "3.042526", "36.766942");

请注意,导航后立即执行此操作可能无法获得所需的效果。您应该将此代码移至LoadCompleted的{​​{1}}事件。