Javascript code _ javascript skills

Source: Internet
Author: User
Obtain the id list of controls containing a string in a container control. // obtain the id list of controls containing a string in a container control.
// Parameter: Container Control, id keyword of the control to be searched, and Tag Name of the control to be searched
// Return value: string of the retrieved Control id list, separated by commas.

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 obtain the control in the GridView.
Improvement: you can remove the TagName parameter.
// Obtain the Control id list containing a string in a container control.
// Parameter: id keyword of the container control and control to be searched
// Return value: string of the retrieved Control id list, separated by commas.

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
// Obtain the control array whose id contains a string in a container control
// Parameter: id keyword of the container control and control to be searched
// Return value: the queried control array

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 Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.