国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database Mysql Tutorial 使用升級(jí)版的 Bootstrap typeahead v1.2.2

使用升級(jí)版的 Bootstrap typeahead v1.2.2

Jun 07, 2016 pm 03:39 PM
bootstrap use

上次介紹了 Bootstrap 2 中附帶的 typeahead,功能強(qiáng)大,但是使用起來不太方便,作者 Terry Rosen 已經(jīng)升級(jí)了一個(gè)新版本 v1.2.2,作出了很大的改進(jìn)。 下載地址 https://github.com/tcrosen/twitter-bootstrap-typeahead 使用環(huán)境 Twitter Bootstrap 2.0 jQue

上次介紹了 Bootstrap 2 中附帶的 typeahead,功能強(qiáng)大,但是使用起來不太方便,作者 Terry Rosen 已經(jīng)升級(jí)了一個(gè)新版本 v1.2.2,作出了很大的改進(jìn)。

下載地址

https://github.com/tcrosen/twitter-bootstrap-typeahead

使用環(huán)境

  • Twitter Bootstrap 2.0+
  • jQuery 1.7+

頁面準(zhǔn)備

<span><span>link </span><span>href</span><span>="/path/to/bootstrap.css"</span><span> rel</span><span>="stylesheet"</span><span>></span>
<span><span>script </span><span>src</span><span>="/path/to/jquery.js"</span><span> type</span><span>="text/javascript"</span><span>></span><span>script</span><span>></span>
<span><span>script </span><span>src</span><span>="/path/to/bootstrap-typeahead.js"</span><span> type</span><span>="text/javascript"</span><span>></span><span>script</span><span>></span></span></span></span>

腳本

$(myElement).typeahead(options);

事件

事件 說明
grepper Filters relevant results from the source.
highlighter Highlights any matching results in the list.
itemSelected 當(dāng)選中一個(gè)項(xiàng)目時(shí)的回調(diào)函數(shù).
  • item: 選中的 HTML 元素
  • val: *val* 屬性的值
  • text: *display* 屬性的值
lookup Determines if source is remote or local and initializes the search.
matcher Looks for a match between the query and a source item.
render Renders the list of results.
select Selects an item from the results list.
sorter 排序結(jié)果.

初始化參數(shù)

名稱 類型 默認(rèn)值 說明
ajax object
{
    url: null,
    timeout: 300,
    method: 'post',
    triggerLength: 3,
    loadingClass: null,
    displayField: null,
    preDispatch: null,
    preProcess: null
}
The object required to use a remote datasource.?
See also: ajax as a string (below)
ajax string null Optionally, a simple URL may be used instead of the AJAX object.?
See also: ajax as an object (above)
display string 'name' The object property to match the query against and highlight in the results.
item string '
  • '
    The HTML rendering for a result item.
    items integer 8 The maximum number of items to show in the results.
    menu string '' The HTML rendering for the results list.
    source object [] The source to search against.
    val string 'id' The object property that is returned when an item is selected.

    基本使用

    如果使用本地?cái)?shù)據(jù)的話直接使用 source

    <span>var</span> mySource = [{ id: 1, name: 'Terry'}, { id: 2, name: 'Mark'}, { id: 3, name: 'Jacob'<span>}];
    
    $(</span>'#myElement'<span>).typeahead({
        source: mySource
    });</span>

    如果使用 Ajax 的話,可以直接指定 url,注意,現(xiàn)在的版本要求必須使用對(duì)象形式的數(shù)據(jù)源,默認(rèn)顯示文本為對(duì)象的 name 屬性,可以通過初始化參數(shù)的 display 配置,默認(rèn)的標(biāo)識(shí)屬性為 id ,可以使用 val 進(jìn)行配置。

    $('#myElement'<span>).typeahead({
        ajax: </span>'/path/to/mySource'<span>
    });</span>

    ?

    使用 Ajax

    使用升級(jí)版的 Bootstrap typeahead v1.2.2

    $(<span>function</span><span> () {
        $(</span>'#product_search'<span>).typeahead({
            ajax: {
                url: </span>'@Url.Action("AjaxService")'<span>,
                timeout: </span>300,                   <span>//</span><span> 延時(shí)</span>
                method: 'post'<span>,
                triggerLength: </span>3,               <span>//</span><span> 輸入幾個(gè)字符之后,開始請(qǐng)求</span>
                loadingClass: <span>null</span>,             <span>//</span> 加載數(shù)據(jù)時(shí), 元素使用的樣式類<span>
                preDispatch: </span><span>null</span><span>,        // 發(fā)出請(qǐng)求之前,調(diào)用的預(yù)處理方法
                preProcess: </span><span>null         // Ajax 請(qǐng)求完成之后,調(diào)用的后處理方法</span><span>
            },
            display: </span>"name",     <span>//</span><span> 默認(rèn)的對(duì)象屬性名稱為 name 屬性</span>
            val: "id",           <span>//</span><span> 默認(rèn)的標(biāo)識(shí)屬性名稱為 id 屬性</span>
            items: 8,            <span>//</span><span> 最多顯示項(xiàng)目數(shù)量</span>
            itemSelected: <span>function</span> (item, val, text) {      <span>//</span><span> 當(dāng)選中一個(gè)項(xiàng)目的時(shí)候,回調(diào)函數(shù)</span>
    <span>            console.info(item);
            }
        });
    });</span>

    使用升級(jí)版的 Bootstrap typeahead v1.2.2

    ?如果我們需要在請(qǐng)求中,除了遞進(jìn)搜索的參數(shù)之外,添加額外的請(qǐng)求參數(shù)怎么辦呢,可以通過 preDispatch 進(jìn)行額外處理,需要注意的是,一定要返回一個(gè)對(duì)象,這個(gè)對(duì)象將用來使用 jQuery 的 Ajax 方法作為參數(shù)。

    使用升級(jí)版的 Bootstrap typeahead v1.2.2

     $(<span>function</span><span> () {
            $(</span>'#product_search'<span>).typeahead({
                ajax: {
                    url: </span>'@Url.Action("AjaxService")'<span>,
                    timeout: </span>300,                   <span>//</span><span> 延時(shí)</span>
                    method: 'post'<span>,
                    triggerLength: </span>3,               <span>//</span><span> 輸入幾個(gè)字符之后,開始請(qǐng)求</span>
                    loadingClass: <span>null</span>,             <span>//
    </span>                preDispatch: <span>function</span><span> (query) {
                        </span><span>var</span> para = { other: 'xxxxxxxxx'<span> };
                        para.query </span>=<span> query;
                        </span><span>return</span><span> para;
                    },
    
                    preProcess: </span><span>function</span><span> (result) {
                        </span><span>return</span><span> result;
                    }
                },
                display: </span>"name",     <span>//</span><span> 默認(rèn)的對(duì)象屬性名稱為 name 屬性</span>
                val: "id",           <span>//</span><span> 默認(rèn)的標(biāo)識(shí)屬性名稱為 id 屬性</span>
                items: 8,            <span>//</span><span> 最多顯示項(xiàng)目數(shù)量</span>
                itemSelected: <span>function</span> (item, val, text) {      <span>//</span><span> 當(dāng)選中一個(gè)項(xiàng)目的時(shí)候,回調(diào)函數(shù)</span>
    <span>                console.info(item);
                    </span><span>//</span><span> console.info($("#product_search").val());</span>
    <span>
                }
            });
        });</span>

    使用升級(jí)版的 Bootstrap typeahead v1.2.2

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1502
    276
    How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

    Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

    How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

    There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

    How to verify bootstrap date How to verify bootstrap date Apr 07, 2025 pm 03:06 PM

    To verify dates in Bootstrap, follow these steps: Introduce the required scripts and styles; initialize the date selector component; set the data-bv-date attribute to enable verification; configure verification rules (such as date formats, error messages, etc.); integrate the Bootstrap verification framework and automatically verify date input when form is submitted.

    How to get the bootstrap search bar How to get the bootstrap search bar Apr 07, 2025 pm 03:33 PM

    How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

    How to view the date of bootstrap How to view the date of bootstrap Apr 07, 2025 pm 03:03 PM

    Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.

    How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

    How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

    10 latest tools for web developers 10 latest tools for web developers May 07, 2025 pm 04:48 PM

    Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

    How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

    To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

    See all articles