Source: http://www.cnblogs.com/JeffreyZhao/archive/2009/10/12/code-for-fun-tokenizer.html
Today, I tried it again by mistake, including the following two answers:
Http://www.cnblogs.com/jeffreyzhao/archive/2009/10/21/code-for-fun-tokenizer-answer-1
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Script
Type
= "Text/JavaScript"
>
Function
Getvalue (name){
VaR
Str
=
Window. Location. search;
If
(Str.
During ASP. NET development, page garbled characters are frequently encountered. The following information is collected on the Internet. For more information, see:
The following reproduced from: http://blog.csdn.net/echsys/archive/2008/03/12/217412
CopyCodeThe Code is as follows: var ID;
Function GETID ()
{
VaR url = location. search;
VaR request = new object ();
If (URL. indexof ("? ")! =-1)
{
VaR STR = URL. substr (1) // remove? No.
STRs = Str. Split ("&");
For (VAR I = 0; I {
// Get the parameter after the URL: User Name
Loadvariables ("", U );
Uname. Text = u;
Htm:
VaR FLA = '';FLA + = ' ';FLA + = ' ';FLA + = ' ';FLA + = ' ';Document. Write (FLA );
Copy codeThe Code is as follows: (function (){
Var urlToObject = function (url ){
Var urlObject = {};
If (/\? /. Test (url )){
Var urlString = url. substring (url. indexOf ("? ") + 1 );
Var urlArray = urlString. split ("&");
For (var I = 0,
Currently, webpage processing often involves processing address bar parameters, but it has always been done by feeling, and I don't know where to change it. Therefore, I made a special method to modify the parameters in the address bar, so I don't
Before modification:
Copy codeThe Code is as follows:
After modification:Copy codeThe Code is as follows:
Thanks to the grass-roots programmers for rewriting this method. It is more rigorous and efficient. I will study it later !!!Copy codeThe
Of course, we can also use regular expressions for direct matching. This article also provides an example of regular expressions.Link decomposition method: Copy codeThe Code is as follows: Regular Expression matching:Copy codeThe Code is as follows:
Function CodeCopy codeThe Code is as follows:Function parseURL (url ){Var a = document. createElement ('A ');A. href = url;Return {Source: url,Protocol: a. protocol. replace (':',''),Host: a. hostname,Port: a. port,Query: a. search,Params: (function
Of course, we can get the parameter value in the background, and then get the variable value in the front-end js Code. For details, refer to my article: javaScript obtains the C # variable in the background and calls the background method.In fact,
The function description is as follows:Code
// Get Params form URL dml@2012.10.31function getrequest () {var url = location. Search; // get URL in "? "Var therequest = new object (); If (URL. indexof ("? ")! =-1) {var STR = URL. substr (1); STRs =
In the project, you need to obtain the get parameter through JS, find the following plug-in on the Internet:
For example, your url is:Http://www.xxx.com/index.php? Test = 1 & KK = 2
If you want to obtain test, you can introduce the
1. for Chinese characters and some non-URL strings, use stringbyaddingpercentescapesusingencoding:
Nsstring * escapedurlstring = [unescapedstring stringbyaddingpercentescapesusingencoding: nsasciistringencoding];
2. The above method does not work
function geturlarg (seekarg) { var url = location. href; // use regular expressions to separate the parameters between the question mark and the well number, such as from the http://www.jb51.net/testjs.htm? P = 1 & t = 1 & U = 1 # In test, P = 1 &
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.