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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了php通过iframe实现局部刷新,包括了iframe方面的内容,希望对PHP教程有兴趣的朋友有所帮助。