日期:2014-05-16  浏览次数:20392 次

怎么样获得页面内所有“id号以cat10开头,以000结尾”的对象?
如题

------解决方案--------------------
呵呵,简单实现,启发一下,哈

<html>
<head>
<title> New Document </title>
</head>

<body>
<textarea id= "ttaOne " rows= "5 " cols= "30 "> </textarea>
<textarea id= "ttaTwo " rows= "5 " cols= "30 "> </textarea>
<textarea id= "cat10ttaTwo000 " rows= "5 " cols= "30 "> </textarea>
</body>
<script language= "JavaScript ">
<!--
var colAll = document.getElementsByTagName( "* ");

var re = /^cat10(\w)*000$/gi;

for (var i=0; i <colAll.length; i++)
{
if (colAll[i].id)
{
if (colAll[i].id.match(re))
{
alert(colAll[i].id + " have been found. Do what you want! ");
}
}
}
//-->
</script>
</html>
------解决方案--------------------
<input id= "cat1011000 ">
<input id= "a " onchange= "return check(this.value) ">
<script>
o = document.all;
p = /^cat10.*000$/;
for(c=0;c <o.length;c++)
{
if(p.test(o[c].id)) alert(o[c].id);
}
</script>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 取对象 </title>
<script type= "text/javascript ">
var search = {
array : [],
parse : function (o) {
var wc = this, a = o.childNodes, i;
if (a) {
for (i = 0 ; i < a.length ; i ++) {
if (a[i].nodeType == 1) {
if (/^cat10.*000$/.test(a[i].id)) wc.array[wc.array.length] = a[i].id;
wc.parse(a[i]);
}
}
}
}
};
window.onload = function () {
search.parse(document.body);
alert(search.array.join( "\n "));
};
</script>
</head>
<body>
<div id= "cat10_01_000 ">
<div id= "cat10_05_000 ">
<div id= "cat10_06_000 ">
<div id= "cat10_07_000 ">
<div id= "cat10_08_000 ">
<div id= "cat10_09_000 "> </div>
</div>
</div>
</div>
</div>
</div>
<div id= "cat10_02_000 "> </div>
<div id= "cat10_03_000 "> </div>
<div id= "cat10_04_000 "> </div>
<div id= "cat10000 "> </div>
<div id= "cat1000 "> </div>
</body>
</html>