问题描述
我有几个< div id =''DivNumber1''>在我的页面上。
Id可以是1到65535之间的随机数。
我需要一个脚本,我可以获取所有div标签并检查是否ID为
DivNumber。
这不起作用:
if(document.getElementById)
{
var ar = document.getElementsByTagName(" DIV");
for(var i = 0; i< ar.length; i ++)
{
s1 = new String(ar [i] .id);
if(s1.search(''GroupItem'')> = 0)ar [i] .style.display =" none" ;;
}
}
简化:
if (document.getElementsByTagName){
var ar = document.getElementsByTagName(" DIV");
for(var i = 0; i< ar.length; i ++)
if(/DivNumber/.test(ar[i].id))
ar [i] .style.display =" none" ;;
}
-
Evertjan。
荷兰。
(替换所有在我的电子邮件地址中都带点圆点)
I have several <div id=''DivNumber1''> on my page.
the Id can be a random number between 1 and 65535.
I need a script where I can get all div tags and check if the ID is
DivNumber.
This does not work:
if(document.getElementById)
{
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
{
s1 = new String(ar[i].id);
if(s1.search(''GroupItem'')>=0) ar[i].style.display = "none";
}
}
Simplified:
if(document.getElementsByTagName) {
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
if (/DivNumber/.test(ar[i].id))
ar[i].style.display = "none";
}
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
这篇关于标签ID名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!