【问题标题】:How to set s:hidden value from another JSP element如何从另一个 JSP 元素设置 s:hidden 值
【发布时间】:2013-05-03 10:02:54
【问题描述】:

我有以下形式:

<s:form id="storno_form"
    namespace="namespace"
    action="action">

    <sj:submit id="submitId"
        key="btn.show" targets="cancelation_content"
        cssClass="button" validate="true">
    </sj:submit>
</s:form>

表格外是:

<sj:select
    href="%{getUrl}"
    id="selectCampaign"
    autocomplete="true"
    selectBoxIcon="true"
    key="select.campaign"
    name="campaignId"
    list="campaigns"
    listKey="id"
    listValue="name"
    headerKey="-1"
    headerValue="%{getText('select.headerValue')}"
    onSelectTopics="realod"
    onCompleteTopics="customizeAutoCompleter"
/>

如何使用表单提交选择元素的值: 我试过了:

<s:form id="storno_form"
    namespace="namespace"
    action="action">
    <s:hidden  value="%{'campaignId'}" name="campaignId" />
    <sj:submit id="submitId"
        key="btn.show" targets="cancelation_content"
        cssClass="button" validate="true">
    </sj:submit>
</s:form>

但它不起作用?

【问题讨论】:

  • 我并没有真正阅读整个内容,但考虑到隐藏值的问题,您意识到表达式 %{'campaignId'} 将始终评估为“campaignId”。不带引号的campaignId 将查看动作,并且多个带单引号的字符将评估为字符串(单个字符转换为字符,然后所有内容当然会在输出中转换为字符串)。

标签: java jquery jsp struts2 struts2-jquery


【解决方案1】:

你可以用javascript做到这一点

onchange="var el=document.getElementById('selectCampaign');document.getElementById('storno_form')['campaignId'].value=el.options[el.selectedIndex].value;"

同样你可以做onclick&lt;sj:submit标签的事件。

使用 jQuery 更简单

$(document).ready(function() {
  $('#selectCampagn').change(function() {
   var val = $('#selectCampagn').val();
    $('input[name=campaignId]').val(val);
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 2014-04-17
    相关资源
    最近更新 更多