我使用以下HTML:
<form action="/User/Account/LogOff" id="logoutForm" method="post">
<button class="float-left submit-button" title="Logoff">Logoff</button>
</form>
我想将其替换为:
<form action="/User/Account/LogOff" id="logoutForm" method="post">
<div class="button" id="logout" title="Logout">
<span>Logout</span>
</div>
</form>
有没有办法可以点击div#logout并将其用作表单的提交?我看到了这个链接:
<a href="javascript:document.getElementById('logoutForm').submit()">Logout</a>
但我怎么能像我这样的DIV呢?
答案 0 :(得分:1)
将此添加到您的DIV中:
<div class="button" id="logout" onclick="javascript:document.getElementById('logoutForm').submit();" title="Logout">
编辑1: 谢谢你指出。
<div class="button" id="logout" onclick="submitForm()" title="Logout">
使用Javascript:
function submitForm()
{
document.getElementById('logoutForm').submit();
}