我想突出显示我在自动填充搜索栏中输入的单词

时间:2016-09-06 07:17:42

标签: javascript php jquery

I want to achieve this in below mention code need 我想突出显示自动完成的文本,如上面添加的图片

<?php 
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
global $wpdb;
    // escape values passed to db to avoid sql-injection
$depts = $wpdb->get_results( "SELECT * FROM wp_paklog_service WHERE service_name LIKE '".$query."%'" );
$suggestions = array();
$data = array();
foreach($depts as $row) {
        $suggestions[] = $row->service_name;
        $data[] = $row->id;
}
json_encode ($suggestions);
?>
//this is js code 
var obj = <?php echo json_encode($suggestions); ?>;
jQuery(".search-services").autocomplete({
      source: function( request, response ) {
      var matcher = new RegExp( "^" + jQuery.ui.autocomplete.escapeRegex( request.term ), "i" );
      response( jQuery.grep( obj, function( item ){
          return matcher.test( item );

      }) );
  }

0 个答案:

没有答案