Background
Or the relationship between the school and the major. I need to keep the value before submission in the select statement on the page after clicking the submit button.
There are several methods on the internet, either to return the page through parameters included in the url jump, or to save the select value in the cookie when submitting, and then enter the value in the cookie back to the select.
The select value remains unchanged after the refresh is implemented according to the method saved in the cookie, and an onchange event is set for the select statement.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Window. onload = function (){
Var cooki = document. cookie;
If (cooki! = ""){
Cooki = "{\" "+ cooki + "\"}";
Cooki = cooki. replace (/\ s */g ,""). replace (/=/g ,'":"'). replace (// g ,'","');
Var json = eval ("(" + cooki + ")"); // convert coolies into a json object
Document. getElementById ("selectID"). options [json. selIndex]. selected = true; // keep the original options
}
Else
Save ();
}
Function change ()
{
SelectIndex = document. getElementById ("selectID"). selectedIndex;
Document. cookie = 'selindex = '+ selectIndex; // save it in the cookie with the key name selIndex
}
</Script>