首页  >  文章  >  后端开发  >  php通过iframe实现局部刷新 iframe 刷新 iframe src 获取iframe中的元素

php通过iframe实现局部刷新 iframe 刷新 iframe src 获取iframe中的元素

WBOY
WBOY原创
2016-07-29 08:49:461711浏览

reg.html
reg.html页面中有个iframe标签,通过iframe去请求php校验用户名是否可用。

<code><span><span>html</span>></span><span>head</span>><span>meta</span><span>charset</span>=<span>"utf-8"</span>><span>title</span>> iframe局部刷新<span><span>title</span>></span><span><span>head</span>></span><span>body</span>><span>form</span><span>method</span>=<span>"post"</span><span>action</span>=<span>""</span>>
    用户名:<span>input</span><span>type</span>=<span>"text"</span><span>id</span>=<span>"uname"</span><span>name</span>=<span>'username'</span> /><span>span</span><span>id</span>=<span>"msg"</span><span>style</span>=<span>"color:red;"</span>><span><span>span</span>></span><span><span>form</span>></span><span>iframe</span><span>border</span>=<span>'0'</span><span>width</span>=<span>'0'</span><span>height</span>=<span>'0'</span><span>id</span>=<span>'myiframe'</span> ><span><span>iframe</span>></span><span>script</span><span>type</span>=<span>"text/javascript"</span>><span><span>//当用户名输入框失去焦点时让iframe请求check_reg.php</span>
      document.getElementById(<span>'uname'</span>).onblur = <span><span>function</span><span>()</span>{</span><span>if</span>(<span>this</span>.value != <span>''</span>)
          {
             document.getElementById(<span>'myiframe'</span>).src = <span>'check_reg.php?username='</span>+ <span>this</span>.value;
          }

      }


    </span><span><span>script</span>></span><span><span>body</span>></span><span><span>html</span>></span></code>

check_reg.php

<code><span><span><?php </span>header(<span>"content-type:text/html;charset=utf-8"</span>);
<span>$username</span>  = <span>$_GET</span>[<span>'username'</span>];

<span>if</span>(<span>$username</span> == <span>'admin'</span>)
{
    <span>$msg</span> = <span>'对不起,用户名已被使用!'</span>;
}<span>else</span>
{
    <span>$msg</span> = <span>'恭喜!该用户名可以使用。'</span>;
}


<span>echo</span><span>
  window.parent.document.getElementById('msg').innerHTML = "$msg";

STR;</span><span>?></span></span></span></code>

html iframe,iframe用法,iframe 自适应高度,iframe 滚动条,iframe调用父页面方法,iframe 跨域,iframe 刷新,iframe src,获取iframe中的元素

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了php通过iframe实现局部刷新,包括了iframe方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn