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.