iframe标签实现form表单提交无页面刷新(不需要js)---解析

来源:互联网 发布:网络喷嘴 编辑:程序博客网 时间:2024/05/16 12:54

先看一段代码(PHP例子)

1、表单代码(form.php):

[php] view plaincopy
  1. <?php  
  2. header("Content-type: text/html; charset=utf8");  
  3. ?>  
  4. <iframe name="testIframeName" style="display:none;"></iframe>  
  5. <form target="testIframeName" method="post" action="formAction.php">  
  6. <input type="text" name="username"/>  
  7. <input type="password" name="password"/>  
  8. <input type="submit" value=" 提 交 " />  
  9. </form>  

2、action代码(formAction.php):

[php] view plaincopy
  1. <?php  
  2. echo "<script>alert('test....');</script>";  
  3. ?>  

OK,上面的代码非常简单,但实现了表单提交无刷新....哪这是为什么呢?

哦~其实很基础的东西......就是form标签的属性问题.....如图:



OK,解释就到这里了,虽然例子很简单,很基础....但大多数人不太清楚怎么回事

0 0