-1

2 つのファイルを使用して検索します。 index.htmlPHP 検索関数を呼び出すフォームを作成します ( ss.php)

index.html コード:

<form action="ss.php" method="get">
     <input name="q" type="text"> 
     <input type="submit"> 
</form>

および ss.php コード (php 検索機能):

<?php
  $dir = 'ups';
  $exclude = array('.','..','.htaccess');
  $q = (isset($_GET['q']))? strtolower($_GET['q']) : '';
  $res = opendir($dir);
  while(false!== ($file = readdir($res))) {
    if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {
      echo "<a href='$dir/$file' target = '_blank'>$file</a>";
      echo "<br>";
    }
  }
closedir($res);
?>

入力パラメータの長さが 8 桁のときに検索を開始したい。

編集:

解決されたすべてのボディのおかげで、私はこのコードを使用しました:

<form action="ss.php" method="get"><input name="q"
type="text" pattern=".{8,10}" title="8 to 10 characters" maxlength="10">
<input type="submit"></form>
4

3 に答える 3

2
$(textbox).keypress(function() {
    if(this.length >7 {   
       //ajax call
    }
});

これはあなたが必要とするフォーマットです

于 2013-07-25T14:22:01.870 に答える
1

最も簡単な方法は、ユーザーが 8 文字を入力したときに送信イベントを添付することです。

この onkeyup="..." イベントを試してください:

<input name="q" type="text" onkeyup="if (this.value.length >= 8) { document.forms[0].submit() }">

編集:

上記では、8 文字を超えることはできません。jquery を使用している場合は、これを試してください。

onkeyup="if (this.value.length >= 8) { $.post('/form-action', { q: this.value }, function(response){ alert(response); }); }"
于 2013-07-25T14:21:59.197 に答える
0

html:

<form id='form' action="ss.php" method="get">
    <input id='input' name="q" type="text"/> 
     <input type="submit"/> 
</form>  

JavaScript:

var form = document.getElementById('form');
var input = document.getElementById('input');

input.onkeypress = function(){
    if(input.value.length >= 8){
        form.submit();
    }

}
于 2013-07-25T14:26:35.983 に答える