Petelai project experience Collection (1) ___ js get the value from the previous page url, petelai ___ js

Source: Internet
Author: User

Petelai project experience Collection (1) ___ js get the value from the previous page url, petelai ___ js

Page Jump code: src = "AddCLFFour. aspx? ID = <% = Request. queryString ["ID"]. toString () %> ">, through" Request. queryString ["ID"]. toString () "transmits the parameter ID to AddCLFFour. On the AddCLFFour page, how does one obtain the ID value transmitted from the page?

The following three methods are provided to briefly describe how to implement js to obtain the values from the previous page.

 

1. The simplest method

var wxjdid= <%=Request.QueryString["ID"]%>;

Obtain the ID through Request. QueryString.

2. Use AddCLFFour background

Public string strwxjd; // The background variable strwxjd = Request. QueryString ["ID"]. ToString (); // receives the passed ID.

In js, you can receive the ID.

var wxjdid="<%= strwxjd%>";

 

3. Using a function in js

 function getParameterByName(name) {           name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");           var regexS = "[\\?&]" + name + "=([^&#]*)";            var regex = new RegExp(regexS);           var results = regex.exec(window.location.search);             if (results == null)                    return null;            else                    return decodeURIComponent(results[1].replace(/\+/g, " "));          }


Call the getParameterByName () method in js.

var wxjdid=getParameterByName(ID); 


For this problem, only the implementation of these three methods is verified. This problem is generated by the project. Although it is very simple, I think it is necessary to sort it out.

 


The thinkphp framework is a project. If you want to transfer a value from the Controller to js on the html template page, how can you get this value in js?

1) write in the controller:
$ This-> assign ("aaaa", $ str );
2) write in the template:
<Script>
Alert ('{$ aaaa }');
</Script>

How to Use jquery to obtain the value in the hyperlink

This function is available in js:
Window. location. href: set or retrieve the entire URL as a string
Window. location. pathname: set or obtain the specified file name or path of the object.
Window. location. search: set or obtain the Section following the question mark in the href attribute.
To obtain the value of a variable, try:
Var urlParam = window. location. search;
Var loc = urlParam. substring (urlParam. lastIndexOf ('=') + 1, urlParam. length );
If multiple parameters can be split, multiple key-value pairs are obtained.
Hope to help you.

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.