form表单只交付值,而不进行页面跳转
form表单只提交值,而不进行页面跳转
嗯,主要原理是jquery手动提交form。并且return false不让自动提交触发
你说的这种我还真没见过,是定位到自己的iframe吧
一般的form提交操作写法为
<form action="saveReport.htm" method="post"> …… <input type="submit" value="保存报告"/> </form>
点击submit按钮或直接回车可以将数据提交到saveReport页面,但是提交后也会跳转到saveReport页面
如何做到
将数据提交到saveReport(form的action指向)页面,但是页面又不进行跳转,即保持当前页面不变呢??
这种需要在load一个页面的时候尤其迫切。
利用jquery的ajaxSubmit函数以及form的onsubmit函数完成,如下:
<form id="saveReportForm" action="saveReport.htm" method="post" onsubmit="return saveReport();"> <input type="submit" value="保存报告"/> </form>
form增加一个id用于在jquery中调用,增加一个onsubmit函数用于submit前自己提交表单
saveReport对应函数为
function saveReport() { // jquery 表单提交 $("#showDataForm").ajaxSubmit(function(message) { // 对于表单提交成功后处理,message为提交页面saveReport.htm的返回内容 }); return false; // 必须返回false,否则表单会自己再做一次提交操作,并且页面跳转 }
上述js已经进行注释
1 楼
fhqllt
2011-09-29
这个确实算是一种方式,以前用过这种方式:
<form id="form" name="form" method="post" action="saveitem.action"
target="form_iframe" />
<input type="submit" value="保存报告"/>
<form>
<iframe name="pfForm_iframe" width="0" height="0" scrolling="no">
</iframe>
<form id="form" name="form" method="post" action="saveitem.action"
target="form_iframe" />
<input type="submit" value="保存报告"/>
<form>
<iframe name="pfForm_iframe" width="0" height="0" scrolling="no">
</iframe>
2 楼
Trinea
2011-09-30
fhqllt 写道
这个确实算是一种方式,以前用过这种方式:
<form id="form" name="form" method="post" action="saveitem.action"
target="form_iframe" />
<input type="submit" value="保存报告"/>
<form>
<iframe name="pfForm_iframe" width="0" height="0" scrolling="no">
</iframe>
<form id="form" name="form" method="post" action="saveitem.action"
target="form_iframe" />
<input type="submit" value="保存报告"/>
<form>
<iframe name="pfForm_iframe" width="0" height="0" scrolling="no">
</iframe>
嗯,主要原理是jquery手动提交form。并且return false不让自动提交触发
你说的这种我还真没见过,是定位到自己的iframe吧