JavaScript gets the HREF connection address in a label and decomposes it

Source: Internet
Author: User

The following code is already in the original page and cannot be changed, and the class label is unique on the page:

The code is as follows Copy Code
<a href= "home-uid-100.html" class= "Noborder" >user100</a>

Now I want to get the link UID number 100 in the a label href, and then put it in the new link, such as:

The code is as follows Copy Code

<a href= "h_id=100" >user100</a>


<a class= "Noborder" href= "home-uid-100.html" > Lulu blog </a>

</body>
<script language= "JavaScript" >
<!--
Description: The way Javascript gets the href of a tag and decomposes it

function/42833.htm target=_blank > Global variables, getting the parameter values in the link
var value = "";

function Get ()
{
Search all a tags and keep them in _el
var el = [],
_el = document.getElementsByTagName (' a ');

/*
* If you are looking for a label with Id= "", such as <a id= "ku" href= "" ></a>
* Then the above two lines can be changed to
* var el = [],
* _el = Document.getelementsbyid (' ku ');
*/

Traverse _el to obtain the href value of a label containing class== "Noborder"
for (var i=0; i<_el.length; i++) {
if (_el[i].classname = = ' Noborder ')
{
Get the A label of the href
value = _el[i].href;

Make a regular match, get the parameter value after the uid-in the href
var re =/uid-([^.] *)/I;

var r = Value.match (re);
Value = R[1];
Break
}
}
}
Execution function
Window.onload = Get

-->
</script>

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.