第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在搜索結(jié)果上添加標簽?

如何在搜索結(jié)果上添加標簽?

慕姐4208626 2024-01-03 15:01:10
如何在搜索結(jié)果上添加標簽?請檢查圖片以供參考我只想將兩個結(jié)果與特定標題分開,我怎樣才能實現(xiàn)這一點?這是我的代碼的結(jié)果供你參考<script>  /* globals global */  jQuery(function($) {    var searchRequest;    $('.search-autocomplete').autoComplete({      minChars: 2,      source: function(term, suggest) {        try {          searchRequest.abort();        } catch (e) {}        searchRequest = $.getJSON(global.ajax, {          q: term,          action: 'search_site'        }, function(res) {          //console.log(res.data);          var suggestions = [];          res.data.forEach(x => {            console.log(x);            if (~x.post_title.toLowerCase().indexOf(term)) {              suggestions.push(x.post_title);            } else if (~x.post_status.toLowerCase().indexOf(term)) {              suggestions.push(x.post_title);            }            suggest(suggestions);          });          //  for (i=0;i<res.data.length;i++)          //       if (~res.data.post_title[i].toLowerCase().indexOf(term)) suggestions.push(res.data.post_title[i]);          //  suggest(suggestions);        });      }    });  });</script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.min.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.css" rel="stylesheet"/><form role="search" method="get" id="searchform" action="http://localhost/gigant-live/">  <div>    <label class="screen-reader-text" for="s">Search for:</label>    <input type="text" autocomplete="off" value="" name="s" class="form-control search-autocomplete" id="s" placeholder="My Search form" />    <input type="submit" id="searchsubmit" value="Search" />    <input type="hidden" name="post_type" value="product" />  </div></form>
查看完整描述

3 回答

?
素胚勾勒不出你

TA貢獻1827條經(jīng)驗 獲得超9個贊

我想你正在尋找這個。jquery/自動完成

$(".search-autocomplete").autoComplete({

        minChars: 1,

        source: function (term, suggest) {

          term = term.toLowerCase();

          var choices = [

            { label: "a", value: "apple" },

            { label: "b", value: "boy" },

            { label: "c", value: "car" },

          ];

          var suggestions = [];

          for (i = 0; i < choices.length; i++)

            if (choices[i].value.indexOf(term) !== -1) {

              suggestions.push(choices[i]);

            }

          suggest(suggestions);

        },

        renderItem: function (item, search) {

          return (

            '<div class="autocomplete-suggestion">' +

            '<span style="color: red; margin-right: 10px">' +

            item.label +

            "</span>" +

            "<span>" +

            item.value +

            "</span>" +

            "</div>"

          );

        },

      });

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.css" rel="stylesheet"/>

<input

      type="text"

      autocomplete="off"

      value=""

      name="s"

      class="search-autocomplete"

      id="s"

      placeholder="My Search form"

    />


查看完整回答
反對 回復(fù) 2024-01-03
?
PIPIONE

TA貢獻1829條經(jīng)驗 獲得超9個贊

https://img1.sycdn.imooc.com/6595067b0001ddae04850330.jpg


您需要創(chuàng)建唯一的標簽集,或者可以循環(huán)遍歷結(jié)果集并僅附加標簽一次

var headers = [];


if(!headers.includes(section[i])){? ?//section will contains the lables? ? ? ? ?

? ? label = document.createElement("H2");?

? ? label.innerHTML = section[i];

? ? headers.push(section[i]);? ? ? ? ? ??

? ? resultSet.appendChild(label);

}


查看完整回答
反對 回復(fù) 2024-01-03
?
縹緲止盈

TA貢獻2041條經(jīng)驗 獲得超4個贊

   function ja_ajax_search() {

    $results = new WP_Query( array(

        'post_type'     => array( 'product','product-tag' ,'post_author'),

        'post_status'   => 'publish',

        'nopaging'      => true,

        'posts_per_page'=> 100,

        's'             => stripslashes( $_POST['search'] ),

    ) );


    $items = array();



    // print_r($results);

    if ( !empty( $results->posts ) ) {


        foreach ( $results->posts as $result) {

            // $services = [$result ];

            $post_details = [

                'post_id' => $result->ID,

                'post_author' => $result->post_author,

                'post_title' => $result->post_title,

                'post_status' => $result->post_status,

                'post_slug' => $result->post_name

            ];

            array_push($items, $post_details);

            // $items[] .= $services;

            // echo $result->post_title;


        }



    }

    // print_r($items);

    // print_r($items);

    // print_r($items);


    // if ( !empty( $results->posts ) ) {


    //     foreach ( $results->posts as $result ) {

    //         $items[] = $result->post_status;

    //     }

    // }





    wp_send_json_success( $items ); 


}

add_action( 'wp_ajax_search_site',        'ja_ajax_search' );

add_action( 'wp_ajax_nopriv_search_site', 'ja_ajax_search' );


查看完整回答
反對 回復(fù) 2024-01-03
  • 3 回答
  • 0 關(guān)注
  • 192 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號