开发者

Javascript loop not seeing asp labels

I have the fo开发者_如何学JAVAllowing javascript in an asp page:

for (var i=0; i < form1.elements.length; i++) {
    var elm = form1.elements[i];
    alert(elm.name)
}

When I iterate throught I see the viewstate and I see the asp buttons but I do not see the asp labels. Is that the expected behavior? How can I iterate through the labels?


not too familiar with asp, but I am pretty sure label tags are not part of the form's elements property. Try something like this

var labels = form1.getElementsByTagName("LABEL");
for(var i=0; i < labels.length; i++) {
    alert(labels[i].id);
}


ASP labels render as SPAN tag and SPAN tag is not part of the forms collection. While you can iterate through the SPAN collection with code given by medina-g (use SPAN instead of LABEL), the typical HTML page may have a lot of spans.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜