java - 如何将国家/地区 ID 传递给 <a href> 标记?

标签 java jsp parameter-passing

我得到了以下代码:

<form method="post" accept-charset="UTF-8" action="showPartners.action?" id="_form" onsubmit="return selCheck();">
<div style="float: left; width: 350px;">
    <span class="text_vert"> Select Country : </span>&nbsp;&nbsp;
    <s:select style="width:200px;" onchange="loadBusinessList();"
    headerKey="-1" headerValue="Country Select" list="couList"
    listKey="idCountry" listValue="label" id="countryId"
    name="countryId">
    </s:select>
</div>

<a href='addPartner.action?height=550&width=850&id=<s:property value="countryId"/>'" >Insert</a>
</form>

我需要做的是将国家/地区 ID 传递给 a href 标记中的链接,但我得到的是 ID=0。

如果有任何帮助,我将不胜感激。

最佳答案

最简单的解决方案是使用 JavaScript,如下所示:

<s:select style="width:200px;" onchange="loadBusinessList();document.getElementById('anchor_id').href=document.getElementById('anchor_id').href.replace(/&id=(?:$|\d+)/, '&id=' + this.value)" ...

还有:

<a id="anchor_id" href='addPartner.action?height=550&width=850&id=0'" >Insert</a>

请注意:代码假定您的国家/地区 ID 是整数。

关于java - 如何将国家/地区 ID 传递给 <a href> 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22807045/

相关文章:

具有构建器模式的 Java 泛型类型 DSL

java - 如何判断 Java 中使用的输入类型

java - 对于未实现 AutoCloseable 的类,使用 lambda 是一种安全、正确且等效的解决方法吗?

java - Java 新手 - 什么是 JPA 和 DAO?

java - 在java spring中生成pdf文件时出错

java - 我不想从 axboot 记录 jpa 查询

python - *(单星)和/(斜线)作为独立参数有什么作用?

javascript - Jquery - IF-ELSE 逻辑不起作用

javascript - Jquery - 动态传递参数给函数

c++ - 在 C++ 中将局部变量传递给函数的最佳方法