简体   繁体   English

传递js变量以形成动作

[英]pass js variable to form action

I have a dynamic variable in js. 我在js中有一个动态变量。 I have to get this variable in my form action. 我必须在表单操作中获取此变量。 Here is my code 这是我的代码

<script type="text/javascript">
    $(document).on('click', 'span', function () {

    var AutoPath = $(this).attr('automationpath');
    // or var AutoPath="Redirect.jsp";
    }
</script>

<form action="%{#AutoPath}" method="get">

    <input name="AutoRun" id="AutoAction" value="Auto Action" type="submit"  />
</s:form>

But this does not redirect to the Redirect.jsp page 但这不会重定向到Redirect.jsp页面

If I manually set as below, it will redirect to the Redirect.jsp 如果我手动进行如下设置,它将重定向到Redirect.jsp

<s:set var="formAction" value="'Redirect.jsp'" />
<s:form action="%{#formAction}" >

    <input name="AutoRun" id="AutoAction" value="Auto Action" type="submit"  />
</s:form> 

Can somebody help me with this. 有人可以帮我这个忙吗?

In your javascript code, you are not inserting the automation path into your markup. 在您的JavaScript代码中,您没有在标记中插入自动化路径。

Instead the code should look something like this: 相反,代码应如下所示:

$(document).on('click', 'span', function () {

     //saving the value to variable
     var AutoPath = $(this).attr('automationpath');

     //Inserting value int he form
     $('form').attr('action', autoPath);

})

我不知道您要做什么,但是如果您想更改表单元素的action属性,则只需执行以下操作:

 $('form').attr('action','Redirect.jsp');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM