谷歌地图-Javascript与ASP经典循环不重复
google maps - Javascript with ASP classic loop not repeating
我在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>
当循环运行时,javascript只在元素内部显示一次。
<%=brokeridnum%>在JS中插入一个数字,从chrome中查找源代码可以正常工作。
id为brokeridnum的元素也在工作。
<script type="text/javascript">
initialize();
showLocation("postcode1","<%=destpc%>");
</script>
<p id="<%=rsbkr("broker_id")%>"></p>
这就是这些函数被称为的方式
如有任何帮助,我们将不胜感激!
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.
相关文章:
- jQuery:循环一个具有不同超时值的循环
- 在循环中分配json值时,值被覆盖
- 如何在下面的ES6循环中获得前面的文本
- 为什么“;未定义的“;在JavaScript中结束循环
- Javascript循环不会自我更新
- 如何使用jquery处理php循环通过元素
- 而循环只设置php中输入字段中的第一个值
- 循环遍历数组中的特定索引
- Javascript返回值只在循环中返回一次
- 按照选项卡索引的顺序循环一个jQuery选择
- 循环遍历以数组为值的Javascript对象
- 为什么JavaScript在for循环为3时向所有4发出警报
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 循环结束/推送到数组之前在页面上呈现EJS
- 循环比赛位置算法
- jQuery循环在特定位置暂停
- 我的javascript for循环不起作用
- 循环浏览多个身体背景图像
- W3C循环样式的JavaScript
- 谷歌地图-Javascript与ASP经典循环不重复