Javascript getElementById是另一个问题
作为一个扩展问题,Felix Kling非常出色地回答了这个问题,我现在需要对部署的数据表进行两部分检查 有人能告诉我如何添加到下面的代码中,这样我不仅可以将pcode字段的值复制到数组中,还可以检查复选框中是否有对应行号的复选框,即route2为check,然后添加到数组中,但如果route3未被选中,则将其排除Javascript getElementById是另一个问题,javascript,html,Javascript,Html,作为一个扩展问题,Felix Kling非常出色地回答了这个问题,我现在需要对部署的数据表进行两部分检查 有人能告诉我如何添加到下面的代码中,这样我不仅可以将pcode字段的值复制到数组中,还可以检查复选框中是否有对应行号的复选框,即route2为check,然后添加到数组中,但如果route3未被选中,则将其排除 function GetRoute() { var from = document.getElementById('inpAddr')
function GetRoute()
{
var from = document.getElementById('inpAddr').value;
var locations = [from];
for(var i = 2; i <= 400; i++) {
var element = document.getElementById('pcode' + i);
if(element === null) { break; }
locations.push(element.innerHTML);
}
var options = new VERouteOptions();
options.DrawRoute = true;
options.RouteColor = new VEColor(63,160,222,1);
options.RouteWeight = 3;
options.RouteCallback = onGotRoute;
options.SetBestMapView = true;
options.DistanceUnit = VERouteDistanceUnit.Mile;
options.ShowDisambiguation = true;
map.GetDirections(locations,options);
}
函数GetRoute()
{
var from=document.getElementById('inpAddr').value;
变量位置=[from];
for(vari=2;ifor(vari=2;(element=document.getElementById('pcode'+i))&&ifunction GetRoute(){
var from=document.getElementById('inpAddr').value;
变量位置=[from];
//我的修改从这里开始。。。。
var maxLoopValue=400;
var pcode,currentRoute,nextRoute;
对于(var i=2;i
for( var i = 2 ; (element = document.getElementById('pcode' + i)) && i <= 400; i++ )
{
if( document.getElementById('route' + i).checked )
{
locations.push( element.innerHTML );
}
}
function GetRoute() {
var from = document.getElementById('inpAddr').value;
var locations = [from];
// My Modification Starts Here....
var maxLoopValue = 400;
var pcode, currentRoute, nextRoute;
for(var i = 2; i <= maxLoopValue; i++) {
pcode = document.getElementById('pcode' + i);
currentRoute = document.getElementById('route' + i);
// Make sure the currentRoute is 'checked'
if (currentRoute.checked) {
// Make sure there is a 'next' route before trying to check it
if (i < maxLoopValue) {
nextRoute = document.getElementById('route' + (i+1));
// Make sure the 'next' route is 'checked'
if (nextRoute.checked) {
locations.push(element.innerHTML);
}
} else {
// This is the last route, since we know it's checked, include it
locations.push(element.innerHTML);
}
}
}
// My Modification Ends Here....
var options = new VERouteOptions();
options.DrawRoute = true;
options.RouteColor = new VEColor(63,160,222,1);
options.RouteWeight = 3;
options.RouteCallback = onGotRoute;
options.SetBestMapView = true;
options.DistanceUnit = VERouteDistanceUnit.Mile;
options.ShowDisambiguation = true;
map.GetDirections(locations,options);
}