我有像下面这样的锚标签,我想用输出表格提交输入参数用户名。
<div class="">
<form method="post" id="loginForm" action="<c:url value='/j_security_check'/>" onsubmit="saveUsername(this);
return validateForm(this);" class="form-signin" autocomplete="off" style="left: 20px; position: absolute">
<ul>
<s:textfield id="j_username" name="j_username" placeholder="%{getText('label.username')}" requiredLabel="true" required="true" tabindex="1" cssClass="input-block-level i"/>
<s:password id="j_password" name="j_password" placeholder="%{getText('label.password')}" requiredLabel="true" required="true" tabindex="2" cssClass="input-block-level i"/>
<li>
<button type="submit" class="btn btn-large btn-primary" name="login" tabindex="3">
<i class="icon-lock"></i> <fmt:message key='button.login'/>
</button>
</li>
<li>
<div style="margin-top:20px">
<a class="forgot_password" href="/forgotPassword">Forgot Password</a>
</div>
</li>
</ul>
</form>
</div>
点击表格内的href=/forgot_password
锚点时,我想将j_username
参数发送到动作类。我如何在struts中实现这一点,因为我没有在这里使用表单提交。
答案 0 :(得分:1)
我建议您添加此JavaScript代码并将id="myanchor"
放入忘记密码锚标记中。 href
参数值将被忽略并通过Javascript放置。将onclick="sendUsername()"
放在您的锚标记上。
<script type="text/javascript">
function sendUsername() {
var ctx = '${pageContext.request.contextPath}';
var username = document.getElementById('j_username').value;
document.getElementById('myanchor').href = ctx + "/forgotPassword?j_username=" + username+;
}
</script>
答案 1 :(得分:1)
更改行
<a class="forgot_password" href="/forgotPassword">Forgot Password</a>
到
<a class="forgot_password" href="javascript:location.href='/forgotPassword?j_username='+document.getElementById('j_username').value;">Forgot Password</a>