2013-04-01 5 views
0
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %> 

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
    var directionsDisplay; 
    var directionsService = new google.maps.DirectionsService(); 


    function getParameterByName(name) { 
     name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
     var regexS = "[\\?&]" + name + "=([^&#]*)"; 
     var regex = new RegExp(regexS); 
     var results = regex.exec(window.location.search); 
     if (results == null) 
      return ""; 
     else 
      return decodeURIComponent(results[1].replace(/\+/g, " ")); 
    } 


    function calcRoute() { 

     start = document.getElementById('startvalue').value; 

     end = document.getElementById('endvalue').value; 

     var request = { 
      origin: start, 
      destination: end, 
      travelMode: google.maps.DirectionsTravelMode.DRIVING 
     }; 

     directionsService.route(request, function (response, status) { 
      if (status == google.maps.DirectionsStatus.OK) { 


       directionsDisplay.setDirections(response); 
       this.distance = response.routes[0].legs[0].distance.value/1000; 

      } 
     }); 

    } 



    function Button1_onclick() { 
     calcRoute(); 
    } 

    window.onload = InitializeMap; 
    </script> 


    <div style="height: 86px; width: 689px; margin-left: 16px; margin-top: 0px"> 

     <table style="width: 96%;"> 
      <tr> 
       <td class="auto-style1"> 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
       </td> 
       <td> 
        <asp:TextBox runat="server" id ="startvalue"></asp:TextBox> 
       </td> 
       <td>&nbsp;</td> 
      </tr> 
      <tr> 
       <td class="auto-style2"> 
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
       </td> 
       <td class="auto-style3"> 
        <asp:TextBox runat="server" id ="endvalue"></asp:TextBox> 
       </td> 
       <td class="auto-style3"></td> 
      </tr> 
      <tr> 
       <td class="auto-style1">&nbsp;</td> 

       <td>     
         <input id="Button1" type="button" value="GetDirections" onclick="return Button1_onclick()" /> 

      </tr> 

     </table> 

Button1_onclick() 함수를 호출하고 싶지만 작동하지 않습니다. 이 코드는 아무런 문제가 없습니다. 문제는 함수 호출이 잘못되었습니다. 그래서, 당신이 내가 할 수있는 방법을 말해 줄 수주십시오 ..어떻게이 메서드를 호출 할 수 있습니까?

답변

0

을 그것 때문에 당신의 잘못된 HTML 마크 업

  <tr> 
       <td class="auto-style1">&nbsp;</td> 

       <td>     
         <input id="Button1" type="button" value="GetDirections" onclick="return Button1_onclick()" /> 

</td> <!-- Missing closing tag --> 

      </tr> 
+0

아니요. 문제가되지 않습니다. 여전히 전화 할 수 없습니다 .. 나를 도와주세요. – user2232995

0

이 될 수도 코드를 시도 의 onclick = "자바 스크립트를 반환 : calcRoute()를 대신의 OnClick의 = 마스터 페이지에 다스 려한다

" Button1_onclick를 돌려"이 스크립트 파일 (**<script type="text/javascript" src="../../Scripts/jquery-ui-1.9.2.min.js"></script>**) (모든 최소화 버전)을 확인 ??

   <tr> 
       <td class="auto-style1">&nbsp;</td> 

       <td>     
        <input id="Button1" type="button" value="GetDirections" *onclick="return javascript:calcRoute();"** /> 
       </td>  
      </tr> 

편집 :

$("#filter").click(function(){ 
    Button1_onclick(); 
}); 

<input id="Button1" type="button" value="GetDirections" /> 
+0

그게 문제가 아니에요. 아직도 전화 할 수 없어요. – user2232995

+0

내 편집 된 코드보기 및보기 –

0

당신이 함수 호출의 반환을 제거하는 시도 해 봤나 다른 방법으로 시도? 이 코드는 이벤트를 발생시킵니다.

<asp:Content ID="ContentMain" ContentPlaceHolderID="ContentBody" runat="server">  
    <script type="text/javascript" language="javascript"> 
     function Button1_Click() { 
      alert('foo'); 
     } 
    </script> 
<input type="button" id="Button1" onclick="Button1_Click()" value="GetDirections" /> 

0

왜 그냥 대신 함수를 호출하지?

<input id="Button1" type="button" value="GetDirections" onclick="Button1_onclick()" /> 

그렇지 않으면 Button1_onclick에서 값을 반환해야합니다.

function Button1_onclick() { 
     calcRoute(); 
     return true; 
} 
관련 문제