首頁 >後端開發 >php教程 >php透過iframe實現局部刷新 iframe 刷新 iframe src 取得iframe中的元素

php透過iframe實現局部刷新 iframe 刷新 iframe src 取得iframe中的元素

WBOY
WBOY原創
2016-07-29 08:49:461715瀏覽

reg.html
reg.html頁面有iframe標籤,透過iframe去請求php校驗使用者名稱是否可用。

<code><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>charset</span>=<span>"utf-8"</span>></span><span><<span>title</span>></span> iframe局部刷新<span></<span>title</span>></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>form</span><span>method</span>=<span>"post"</span><span>action</span>=<span>""</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</span><span>id</span>=<span>"msg"</span><span>style</span>=<span>"color:red;"</span>></span><span></<span>span</span>></span><span></<span>form</span>></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></<span>iframe</span>></span><span><<span>script</span><span>type</span>=<span>"text/javascript"</span>></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><<<STR
<script>
  window.parent.document.getElementById('msg').innerHTML = "$msg";
</script>
STR;</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