Home > Web Front-end > JS Tutorial > body text

javascript Get the implementation code of all controls whose ID contains a certain keyword_javascript skills

WBOY
Release: 2016-05-16 18:15:15
Original
1096 people have browsed it

//Get the list of control IDs whose id contains a certain string in a container control
//Parameters: container control, id keyword of the control to be found, label name of the control to be found
//Return value: List string of found control IDs, separated by commas.

Copy code The code is as follows:

function GetIdListBySubKey(container,subKey,TagName)
{
var idList = "";
for(var i = 0; i < container.childNodes.length;i )
{
if(container.childNodes[i].nodeName == TagName && container.childNodes[i].id.indexOf(subKey) > -1)
{
idList = container.childNodes[i].id ",";
}
if( container.childNodes[i].childNodes.length > 0)
{
idList = GetIdListBySubKey(container.childNodes[i],subKey,TagName)
}
}
return idList;
}

can be used to get the controls in GridView.
Improvement: The TagName parameter can be removed
//Get the list of control ids whose id contains a certain string in a container control
//Parameters: container control, id keyword of the control to be found
/ /Return value: The found control ID list string, separated by commas.
Copy code The code is as follows:

function GetIdListBySubKey(container,subIdKey)
{
var idList = "";
for(var i = 0; i < container.childNodes.length;i )
{
if(container.childNodes[i].attributes != null && container.childNodes[i].attributes["id"] != undefined && container.childNodes[i].id.indexOf(subIdKey) > -1)
{
idList = container.childNodes[i] .id ",";
}
if(container.childNodes[i].childNodes.length > 0)
{
idList = GetIdListBySubKey(container.childNodes[i],subIdKey)
}
}
return idList;
}

For example: GetIdListBySubKey(document,"txt_Money")
Improvement: directly return the control array
// Get the control array whose id contains a certain string in a container control
// Parameters: container control, id keyword of the control to be found
// Return value: array of found controls
Copy code The code is as follows:

function GetConListBySubKey(container,subIdKey)
{
var reConArry = [ ];
for(var i = 0; i < container.childNodes.length;i )
{
if(container.childNodes[i].attributes != null && container.childNodes[i] .attributes["id"] != undefined && container.childNodes[i].id.indexOf(subIdKey) > -1)
{
reConArry.push(container.childNodes[i]);
}
if(container.childNodes[i].childNodes.length > 0)
{
var re = GetConListBySubKey(container.childNodes[i],subIdKey)
for(var k = 0;k{
reConArry.push(re[k]);
}
}
}
return reConArry;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template