Upload values between my project 3 js pages and js pages
Because my project requires some simple data passing values between pages, I wrote it in a simple way and shared it with you.
This requires a method if you want to see more details, you can go to W3C to see, here write a link http://www.w3cschool.cc/js/js-window-location.html
On the index.html page, write the following code: a = 1 B = 3 c = 7
Var myurl = "indexshouye.html" + "? "+" 1 = 1 "+" & a = 1 & B = 3 & c = 7 "; window. location. assign (myurl); // send to indexshouye.html
The address of the page to jump to will be: indexshouye.html? 1 = 1 & a = 1 & B = 3 & c = 7
So I need to parse the address in indexshouye.html to get the value I want to pass:
var url=location.href;
// You can try to output urlalert (url );
// Obtain the passed value through the resolution address var tmp1 = url. split ("? ") [1]; var tmp2 = tmp1.split (" & "); a = parseInt (tmp2 [1]. split ("=") [1]); B = parseInt (tmp2 [2]. split ("=") [1]); c = parseInt (tmp2 [3]. split ("=") [1]); // output it to see if it is the value you want alert (a + "--" + B + "--" + c)
Js implements page value transfer
Main.htm assume that a TXT main text box already exists.
Run the following command to call ShowTeatHtml ():
Function ShowTeatHtml (){
Var rtnValue = window. showModalDialog ("test.htm", window,
"Unadorned: yes; help: no; scroll: yes; status: yes ;"
+ "DialogWidth: 800" // width
+ "Px; dialogHeight: 600" // high
+ "Px; center: yes ;");
Document. getElementById ("txtMain"). innerText = rtnValue;
}
Assume test.htm has a button with ID btnReturn \ a text box with ID txtReturn
Set onclick = "CloseAndReturn ();" for btnReturn ();"
Function CloseAndReturn (){
Var rtnTxt = document. getElementById ("txtReturn"). innerText;
Window. returnValue = rtnTxt;
Window. close ();
}
Code with full hands-on at work.
How does JS implement cross-page (HTML) value transfer (20 + 10)
Html. Change the suffix yourself.
A. jsp
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> a </title>
<Script type = "text/javascript">
Function test2 (){
Document. getElementById ("list"). value = <% = session. getAttribute ("select") %>;
}
</Script>
</Head>
<Body onload = "test2 ()">
<Form action = "B. jsp" method = "post">
<Select name = "list" id = "list">
<Option value = null selected = "selected"> -- select -- </option>
<Option value = "1"> name </option>
<Option value = "2"> age </option>
<Option value = "3"> sex </option>
</Select>
<Input type = "submit" value = "submit"/>
</Form>
</Body>
<% Session. removeAttribute ("select"); %>
</Html>
----------------------------------------------
B. jsp
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> B </title>
</He ...... remaining full text>