Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript在onclick中检索变量_Javascript_Jsp - Fatal编程技术网

使用javascript在onclick中检索变量

使用javascript在onclick中检索变量,javascript,jsp,Javascript,Jsp,在使用onclick从javascript函数检索变量后,我试图提交一个JSP页面。有办法吗 Javascript: function sub(str) { alert(str); //To test if I am getting the variable on this function } JSP内容: <c:forEach items="${mybean.flag}" var="element"> <a href="javascript:

在使用onclick从javascript函数检索变量后,我试图提交一个JSP页面。有办法吗

Javascript:

function sub(str)
{
    alert(str); //To test if I am getting the variable on this function
} 
JSP内容:

  <c:forEach items="${mybean.flag}" var="element">
       <a  href="javascript:sub('${element.CASE}');">${element.CASE}</a> 
     </c:forEach>

    <%String w = request.getParameter("str");


    if(!w.equals("null") {
       Call a java bean to do further manipulations
    }

   %>

要根据Javascript提交表单,您可以随时执行以下操作:

document.forms[0].submit(); // assuming you have at least one Form on your page and want to submit the first one

我能够使用下面的代码从onclick传递变量

Javascript:

function sub(str)
{
    alert(str); //To test if I am getting the variable on this function
} 
功能子B(str){

}



它解决不了我的问题。如果您看到我的foreach,我实际上是在尝试使用href提交变量。document.forms[0]。提交不会将该变量带到下一页。谢谢教授,我不太明白你的意思。如果你有一张关于你年龄的表格,我想最好是你加上一个,并填写你的价值。提交后,您就有了可用的值。首先,我认为您不知道如何动态提交表单。
   <a  href="javascript:sub('${element.CASE}');">${element.CASE}</a> 




 </c:forEach>





<%String w = request.getParameter("mydata");




if(!w.equals("null") {




   Call a java bean to do further manipulations




}