1

私は JSON と jQuery に慣れていません。jQuery オートコンプリートを実行する必要があるため、次のようにします。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>


<script>
jQuery(document).ready(function($){
    $('#executives').autocomplete({source:'search_executives.php', minLength:2});
});
</script>

そしてHTMLで:

<div class="rows">
    <div class="labels">Search</div>
    <div class="textboxs" style=" width: 175px;"><input id="executives" name="executive" /></div>
</div>

search_executives.phpは:

<?php
session_start();
    if(empty($_SESSION['userid'])){
        header('Location:index.php');
        exit();
    }
include_once('include/config.php'); 

$qry = "SELECT employee_id,fname,mname,lname FROM personal_details WHERE deg_id = '1'";

$res = $dbo->executeQuery( $qry ) ;

//$results[] = array('label' => $row['name']);

for( $i = 0; $i < count( $res ); $i++ )
{
    $result[] = array( 'label' => $res[$i]['fname'].' '.$res[$i]['mname'].' '.$res[$i]['lname'] , 'value' => $res[$i]['employee_id'] ) ;
}

echo json_encode($result);
?>

今私の問題は -

  1. 入力した検索文字列に依存せず、すべての結果を出力します。
  2. valueHTMLのテキストフィールドに(例 3 )を出力します。幹部の名前をemployee_id彼の値として出力する必要があります。

注意: 第 1 部は解決済みです。LIKEに条件を追加するのを忘れていましたSQL

4

2 に答える 2

1

入力の値を として設定し、アイテムが選択されlabelたときに を格納する別のフィールドを用意する必要があります。employee_id

select: function(e, ui) {
  e.preventDefault();
  this.value = ui.item.label;
  $('#other_field').val(ui.item.value);
}

これが例です

于 2013-06-28T07:47:26.670 に答える
0

入力テキスト ボックスを使用しています。

テキストボックスの値属性はフロントエンドのテキストボックスに表示され、変更できません。(つまり)あなたの場合はemployee_id。

于 2013-06-28T07:25:09.550 に答える