iframe标签实现form表单提交无页面刷新(不需要js)—解析
在FORM表单后添加一个iframe,即<form name='form1' id='form1' action='/xbcw/cw/xx_xx.action' method='post'
target="rfFrame">
target="rfFrame">
<iframe id="rfFrame" name="rfFrame" src="about:blank" style="display:none;"></iframe>
点保存提交事件里面需要将target改为iframe的名字:
JS:document.forms[0].target="rfFrame";
JQuery:$("#f2").attr("target","rfFrame");
这样即提交了FORM保存了数据,页面也不会跳转.
具体的原理是:form表单提交到iframe里面处理,而这个iframe是隐藏的,所以提交表单的时候当前页面没有发生任何变化。form的target属性指向iframe的name值,这样就实现了提交到隐藏的iframe中。
哦~其实很基础的东西......就是form标签的属性问题.....如图: