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> |