1. Access the value returned by JS in JSP:
Problem:
CopyCode The Code is as follows: <script language = "JavaScript">
<! --
VaR STR = "123 ";
<%
String AA;
%>
-->
</SCRIPT>
How can I obtain the STR value in Javascript from AA in this JSP ????
The details are as follows:Copy codeThe Code is as follows: <script language = "JavaScript">
Function returnvalue (){
VaR myform = Document. form1;
VaR STR = myform. text1.value;
<%
String AA;
// How can I make AA equal to STR in JS ???
%>
}
</SCRIPT>
<Form name = "form1">
<Input type = "text" name = "text1" onchange = "returnvalue ();">
</Form>
Solution:
It must be submitted because one is running on the client and the other is running on the server;
Use a hidden field in JSPCopy codeThe Code is as follows: <form name = "form1">
<Input type = "hidden" name = "hide">
</Form>
The script defines var STR = "123 ";
Document. form1.hide. value = STR;
Then, just take the value of hidden.
Problem Comment: In the old saying, JSP must be submitted for obtaining JS data, and JS can directly obtain JSP data.