dynamically remove and add back items to the screen with javascript
I am stuck, I am working with tables so using Div does not seem to work to let me get rid of stuff, but this does work, I just cannot figure out how to use it dynamically.
开发者_Python百科document.all.???.style.display="none"
My idea is to collect the item names in an array and then use the array to remove the desired stuff from the screen. I just cannot figure out how using javascript and vbscript to collect the array, and then to retrieve the value in the javascript function. That same approach works inline with the code, to supress items that I don't want to show such as headings with no detail.
In that case I use a vbscript variable and document.all.<%=x%>.style.display="none";
How can I get X out of the array or directly reference the array in this statement?
You can get an array of the elements with a particular name using document.getElementsByName(nameOfElement);
So something like this should work for you:
var arrayOfElementNames = ['Name1', 'Name2']
for (var nameIndex = 0; nameIndex < arrayOfElementNames.length; nameIndex++) {
var elements = document.getElementsByName(arrayOfElementNames[nameIndex]);
for (var elementIndex = 0; elementIndex < elements.length; elementIndex++) {
elements[elementIndex].style.display = 'none';
}
}
精彩评论