检测表单中的post动作
Detect post action in a form
我想在表单提交时做点什么。
var ispostaction = false;
$("#myform").submit(function () {
ispostaction = true;
});
提交表单时,没有调用.submit(function ())
。我做错什么了吗?我的表单id为myform。
我很感激你的帮助。
这是我的xhtml页面。我使用JSF 2
<form id="myform" class="someclass" enctype="application/x-www-form-urlencoded"
action="pagename.jsf" method="post">
// custom input text field
// selectOneMenu
// a few more input text fields
// submit button is below
<input id="javax.faces.ViewState" type="hidden" autocomplete="off" value="...." name="javax.faces.ViewState">
</form>
jquery文档:
The submit event is sent to an element when the user is attempting to submit
a form. It can only be attached to <form> elements. Forms can be submitted
either by clicking an explicit <input type="submit">, <input type="image">,
or <button type="submit">, or by pressing Enter when certain form elements
have focus.
调用submit函数不会触发submit事件。你可以通过在jquery中添加一个隐藏按钮来"修复"这个问题。不幸的是,大多数(如果不是全部的话)浏览器都显示相同的行为。
<html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<body>
<form id="myform" enctype="application/x-www-form-urlencoded"
action="posturl" method="post">
// custom input text field
// selectOneMenu
// a few more input text fields
// submit button is below
<input id="javax.faces.ViewState" type="hidden" autocomplete="off" value="...." name="javax.faces.ViewState">
<input type="text" value="a value" />
<input id="submit" type="submit" value="submit" style="display: none;" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#myform").bind('submit', function() {
alert('');
});
$("#submit").click();
});
</script>
</body>
</html>
相关文章:
- 如何使用WCF服务和javascript表单post上传.doc文件
- Jquery POST未填充数组
- 如何在php文件中获取$.post-ajax传递的值
- 在POST中将html表作为csv提交
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 如何使用post方法从方法上传文件
- Django: AJAX + CSRF POST gives 403
- AJAX不会在文件上传后重定向到网页-POST方法
- 下载使用POST数据动态生成的文件
- 如何使用自定义标头跨域执行AJAX POST
- 错误405:向Java控制器(Ajax)发送JSON时找不到POST方法
- 检测表单中的post动作
- Http post/get动态动作url
- 没有动作表单POST
- 帆JS在自动路由POST后如何触发动作
- 如何将表单post动作的响应设置为框架源
- 当我想用方法post(javascript)重定向到动作时,控制器方法不重定向并返回到上一页,为什么
- 在动作方法中,如何将post数据绑定到动态对象
- Angular Post函数没有执行的动作
- 在post方法中隐藏表单动作url