如何在Mvc 4中使用Javascript调用提交按钮? [英] How Do I Call Submit Button Using Javascript In Mvc 4 ?
本文介绍了如何在Mvc 4中使用Javascript调用提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在MVC 4中使用javascript调用提交按钮?
我想在点击注销链接时调用注销提交按钮。下面是我的代码,
How do i call Submit button using javascript in MVC 4 ?
I want to call logout submit button on click of log out link. Below is my code,
using (Html.BeginForm("logout", "angular", FormMethod.Post, new { id = "submitForm" }))
{
<button type="submit" id="logoutForm" class="btn btn-success">logout</button>
}
<a id="fgd" href="java<!-- no -->script:document.getElementById('logoutForm').submit()">Log off</a>
但它不起作用:(< br $>
i尝试使用jquery同样但不起作用。这里有什么问题?怎么做?
But it is not working :(
i tried the same using jquery as well but not working. What is the problem here? How to do this?
推荐答案
你可以调用按钮点击事件:
You can either call the buttons click event:
document.getElementById('logoutForm').click();
或者,致电表格提交活动:
Or, call the forms submit event:
document.forms[0].submit();
...希望它有所帮助。
... hope it helps.
这没有任何意义。没有这样的概念,按一个按钮。
提交任何内容意味着发送适当的HTTP请求。为了绕过标准Web表单机制,您可以使用Ajax: http://en.wikipedia.org/wiki/Ajax_ (编程) [ ^ ]。
我想说明你的问题和尝试是设计不太合理的标志,而不仅仅是代码。
-SA
It makes no sense. There is no such concept, "call a button".
To submit anything means sending appropriate HTTP request. To do it bypassing standard Web form mechanism, you can use Ajax: http://en.wikipedia.org/wiki/Ajax_(programming)[^].
I would like to note that your question and attempt are rather the sign of not very reasonable design, not just code.
—SA
这篇关于如何在Mvc 4中使用Javascript调用提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文