Home > front end >  From js values to url hyperlinks inside, for help who help, urgent ~ ~ ~ ~ thank you thank you
From js values to url hyperlinks inside, for help who help, urgent ~ ~ ~ ~ thank you thank you

Time:09-19

From js values to url hyperlinks inside
 

- & gt;

 
Var linkDOM=document. GetElementById (" index ");
Var STR='123-234-456-789',//values from this place, take 234 aaa, BBB take 456, CCC take 789
//aaa take the character after the first rung
//take the character after the second rung BBB
//CCC take the character after the third rung
NewStr=STR. The split (' - '),
LastStr=newStr. Length? NewStr [newStr length - 1] : "',
Href=https://bbs.csdn.net/topics/linkDOM.getAttribute (' href ');

//analysis url
The function parseURL (url) {
Var a=document. The createElement method (' a ');
A.h ref=https://bbs.csdn.net/topics/url;
Return {
Source: url,
Protocol: Amy polumbo rotocol. Replace (' : ', '),
Host: a.h ostname,
Port: Amy polumbo ort,
Query: a.s earch,
Params: (function () {
Var ret={},
Seg=a.s earch. Replace (/^ \?/, "). The split (' & amp; '),
Len=seg. Length, I=0, s;
for (; I & lt; Len. I++) {
if (! Seg [I]) {continue; }
S=seg [I]. The split ('=');
Ret [0] [s] [1]=s;
}
return ret;

}) (),
File: (Amy polumbo athname. Match (/\ [[# ^ \/?] +) $/I) | | [, ' ']) [1],
Hash: a.h ash. Replace (' # ', '),
Path: Amy polumbo athname. Replace (/^//[^ \], '/$1),
Relative: (a.h ref. Match (/TPS? : \/\ [^ \/] + (. +)/) | | [1], ['])
Segments: Amy polumbo athname. Replace (/^///'). The split ('/')
};
}

//replace myUrl name of parameter values
The function replaceUrlParams (myUrl, newParams) {
For (var x in newParams) {
Var hasInMyUrlParams=false;
For (var y in myUrl. Params) {
If (x.t oLowerCase ()==y.t oLowerCase ()) {
MyUrl. Params [y]=newParams [x];
HasInMyUrlParams=true;
break;
}
}
//without an extra
the parameters of the originalif (! HasInMyUrlParams) {
MyUrl. Params [x]=newParams [x];
}
}
Var _result=myUrl. Protocol + "://" + myUrl. Host + ":" + myUrl. Port + myUrl. Path + "?" ;

For (var p in myUrl. Params) {
_result +=(p + "=" + myUrl. Params [p] + & amp; "" );
}

If (_result substr (_result. Length - 1)=="& amp;" ) {
_result=_result. Substr (0, _result. Length - 1);
}

If (myUrl hash! {
="")_result +="#" + myUrl. Hash.
}
Return _result;
}

Var myURL=parseURL (href);
Var _newUrl=replaceUrlParams (myURL, {aaa: lastStr});//aaa as a variable name
Var _newUrl=replaceUrlParams (myURL, {BBB: lastStr});//BBB for variable name
Var _newUrl=replaceUrlParams (myURL, {CCC: lastStr});//CCC for the variable name
Var _newUrl=replaceUrlParams (myURL, {DDD: lastStr});//DDD as the variable name
LinkDOM. SetAttribute (' href '_newUrl);
The console. The log (_newUrl);

CodePudding user response:

No DDD, accidentally written more, don't need DDD
important:
The above js if only for a variable's value on the local computer can be normal access to the last bar at the back of the characters,
On the server will not be able to get into any characters
Like a paranormal problems
bosses look, grateful

CodePudding user response:

 
& lt; Div id="thread_imgid" data - tid="67902" & gt;



//link clickable 
If ($(' thread_mess ') length) {
Var textR=$(' thread_mess '). The HTML ();
Var reg=/(HTTP: \ \/| HTTPS: \ \/) (\ w |=| \? . | the \ | the \ |/& amp; | -) +)/g;
Var imgSRC=https://bbs.csdn.net/topics/$(' thread_mess img '). Attr (" SRC ");
{if (reg. The exec (imgSRC))
Return false
} else {
TextR=textR. Replace (reg, "& lt; A href='https://bbs.csdn.net/topics/$1$2' & gt; $1, $2 & lt;/a>" );
}
Document. The getElementById (' thread_imgid). InnerHTML=textR;
}




The article comes from: https://www.cnblogs.com/chenguiya/p/5221196.html

CodePudding user response:

Big hello
The 123-234-456-789 is written in the js what position?
Also the inside of the url variable names and values of variables would you help me write the?
Now so I can't understand completely
Thank you for your bosses
  • Related