带ASP经典循环的Javascript不重复

带ASP经典循环的Javascript不重复,javascript,google-maps,asp-classic,Javascript,Google Maps,Asp Classic,我在ASP循环中使用以下javascript时遇到了一个小问题 <script type="text/javascript"> var geocoder, location1, location2, gDir; function initialize() { geocoder = new GClientGeocoder(); gDir = new GDirections(); GEvent.addListener(gDir, "load", functio

我在ASP循环中使用以下javascript时遇到了一个小问题

<script type="text/javascript">

var geocoder, location1, location2, gDir;

function initialize() {
    geocoder = new GClientGeocoder();
    gDir = new GDirections();
    GEvent.addListener(gDir, "load", function() {
        var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
        var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
    var drivingTime = gDir.getDuration().html
        document.getElementById("<%=brokeridnum%>").innerHTML = '<strong>Address 1: </strong>' + location1.address + ' <br /><strong>Address 2: </strong>' + location2.address + '<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles.toFixed(2) + ' miles taking ' + drivingTime;
    });
}
</script>
<script type="text/javascript">



    function showLocation(startpc, endpc) {
        geocoder.getLocations(startpc, function (response) {
            if (!response || response.Status.code != 200)
            {
                alert("Sorry, we were unable to geocode the first address");
            }
            else
            {
                location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                geocoder.getLocations(endpc, function (response) {
                    if (!response || response.Status.code != 200)
                    {
                        alert("Sorry, we were unable to geocode the second address");
                    }
                    else
                    {
                        location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                        gDir.load('from: ' + location1.address + ' to: ' + location2.address);
                    }
                });
            }
        });

    }

    </script>

var地理编码器,位置1,位置2,gDir;
函数初始化(){
geocoder=新的GClientGeocoder();
gDir=新的GDirections();
addListener(gDir,“加载”,函数(){
var drivingDistanceMiles=gDir.getDistance().meters/1609.344;
var drivingDistanceKM=gDir.getDistance().meters/1000;
var drivingTime=gDir.getDuration().html
document.getElementById(“”).innerHTML='地址1:'+location1.Address+'
地址2:'+location2.Address+'
行驶距离:'+drivingDistanceMiles.toFixed(2)+“行驶里程数”+驾驶时间; }); } 功能显示位置(startpc、endpc){ geocoder.getLocations(startpc,函数(响应){ 如果(!response | | response.Status.code!=200) { 警报(“抱歉,我们无法对第一个地址进行地理编码”); } 其他的 { location1={lat:response.Placemark[0]。点。坐标[1],lon:response.Placemark[0]。点。坐标[0],地址:response.Placemark[0]。地址}; geocoder.getLocations(endpc,函数(响应){ 如果(!response | | response.Status.code!=200) { 警报(“抱歉,我们无法对第二个地址进行地理编码”); } 其他的 { location2={lat:response.Placemark[0]。点。坐标[1],lon:response.Placemark[0]。点。坐标[0],地址:response.Placemark[0]。地址}; gDir.load('from:'+location1.address+'到:'+location2.address'); } }); } }); }
当循环运行时,javascript只在元素内部显示一次

在JS中插入一个数字,从chrome中查看源代码时,该操作正常工作

id为brokeridnum的元素也在工作

<script type="text/javascript">

   initialize();
   showLocation("postcode1","<%=destpc%>");
   </script>

<p id="<%=rsbkr("broker_id")%>"></p>

初始化();
展览地点(“邮政编码1”);

这就是函数的调用方式

任何帮助都将不胜感激

没有看到整个脚本,我只能猜测。。。
Without seeing the entire script I can only guess...
Maybe instead of looping the entire script, try 
only looping the function call with a   parameter like this:

<% Do   . . . %>
  <script type="text/javascript">
     initialize(<%= brokeridnum %>);
  </script>
<% LOOP . . . %>

The function now outside the loop waits for the brokerid parameter...

function initialize(brokerid){
.....
.....
document.getElementById(brokerid).innerHTML = '......
}

Sorry about abbreviating the code a bit, but I hope I helped.
也许不要循环整个脚本,试试看 仅使用如下参数循环函数调用: 初始化(); 现在循环外的函数将等待brokerid参数。。。 函数初始化(brokerid){ ..... ..... document.getElementById(brokerid).innerHTML='。。。。。。 } 很抱歉对代码进行了一点简化,但我希望我能帮上忙。
您正在使用。您应该尽快将代码移植到(但这不会导致您的问题)。您介意发布包含ASP部分的完整代码吗?从你的描述中,几乎不可能找出什么是错的。JavaScript部分看起来和Google API cal一样好。在我最初的评论之上,您希望看到多少次JavaScript函数(相同)被定义,并且定义出现在您的页面上?那将是1。创建冲突并禁用页面上的所有JavaScript;2.毫无意义。你发布的代码中没有循环。如果没有相关代码,就不可能提供任何帮助。