<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## HTML 頁面 當用戶在上面的輸入框中鍵入字符時,會執行 "showHint()" 函數。該函數由 "onkeyup" 事件觸發: ~~~ <html> <head> <script> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執行的代碼 xmlhttp=new XMLHttpRequest(); } else { //IE6, IE5 瀏覽器執行的代碼 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajax.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <p><b>在輸入框中輸入一個姓名:</b></p> <form> 姓名: <input type="text" onkeyup="showHint(this.value)"> </form> <p>返回值: <span id="txtHint"></span></p> </body> </html> ~~~ 源代碼解釋: 如果輸入框是空的(str.length==0),該函數會清空 txtHint 占位符的內容,并退出該函數。 如果輸入框不是空的,那么 showHint() 會執行以下步驟: * 創建 XMLHttpRequest 對象 * 創建在服務器響應就緒時執行的函數 * 向服務器上的文件發送請求 * 請注意添加到 URL 末端的參數(q)(包含輸入框的內容) ## PHP 文件 上面這段通過 JavaScript 調用的服務器頁面是名為 "ajax.php" 的 PHP 文件。 "ajax.php" 中的源代碼會檢查姓名數組,然后向瀏覽器返回對應的姓名: ~~~ <?php // 將姓名填充到數組中 $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; $a[]="Liza"; $a[]="Elizabeth"; $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky"; //從請求URL地址中獲取 q 參數 $q=$_GET["q"]; //查找是否由匹配值, 如果 q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i<count($a); $i++) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint=$a[$i]; } else { $hint=$hint." , ".$a[$i]; } } } } // 如果沒有匹配值設置輸出為 "no suggestion" if ($hint == "") { $response="no suggestion"; } else { $response=$hint; } //輸出返回值 echo $response; ?> ~~~ 解釋:如果 JavaScript 發送了任何文本(即 strlen($q) > 0),則會發生: 1. 查找匹配 JavaScript 發送的字符的姓名 2. 如果未找到匹配,則將響應字符串設置為 "no suggestion" 3. 如果找到一個或多個匹配姓名,則用所有姓名設置響應字符串 4. 把響應發送到 "txtHint" 占位符
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看