继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

lcript from carol

carolcoral
关注TA
已关注
手记 1
粉丝 4
获赞 0

A simple script for HTML to do. https://carolcoral.github.io/Lcript/

[TOC]

Version:0.1

Features

1.1 First all

1.import these scripts in your page.Beside the Bootstarp and the Jquery should be import at all of scripts first.But the style of Bootstrap is not must be.You can use your own css file.

    <!--have to import jquery first-->
    <script type="application/javascript" src="/src/js/jquery/jquery.js"></script>
    <!--import bootstrap-->
    <script type="application/javascript" src="/src/bootstrap/js/bootstrap.min.js"></script>

2.Then you can import this script in your page to do Search.

    <!--import search javascript-->
    <script type="application/javascript" src="/src/js/search_box/js"></script>

3.Why we should have to import these script?

    Because this script is based on the jquery to do .But you can not have to import the Bootstrap and import what you want a style or theme.

1.2 Then,use it in your page

1.The following attributes are required

    //type of get data,ajax or json
    "url":"/admin/tsg_fuzzy_search",
    //bind method to this element
    "el":obj,
    //show your have searched results
    "el_show":".selected_keywords",
    //refresh the search post time(in ms)
    "refresh":200,
    //set your own type for ajax
    "ajaxType":"post",
    //set the show-tab for search results,must be class,ul style
    "showTabStyle":"list-group",
    //li style
    "listGroupItem":"list-group-item"

2.You can use it like this in your page,and add this code oninput=“test(this)” in your input box.Ofcourse,you can change the “test” to what you want.When you changed it,don’t forget change the function’s name too, please.

    function test(obj){
        lcript.search_ajax({
            "url":"/admin/tsg_fuzzy_search",
            "el":obj,
            "el_show":".selected_keywords",
            "refresh":200,
            "ajaxType":"post",
            "showTabStyle":"list-group",
            "listGroupItem":"list-group-item"
        })
    }

1.3 Importent Notes

1.You have to use “keywords” as your ajax request keyword

2.If you want to do something for a search result,you can create a function which name is “choise_one_template”,then make some methods in it.Like this function:

        //Add the selected template to the display bar
        function choise_one_template(obj) {
            //Get the value of the selection
            var template_data = $(obj).text()
            //Making HTML
            var selected_template_html = 
                "<button type='button' class='btn btn-default template_data' aria-label='Left Align'>"+
                    "<span class='glyphicon glyphicon-remove' aria-hidden='true' ='delete_template(this)'></span>"
                    +selected_template+
                "</button>"
            //Insert HTML into the specified div
            $("#results_2").append(selected_template_html)
        }

3.Request: use “keywords” as your request keyword.

4.Response: “data” is must.If your datatype is json in this response, you have to edit the 102 line in lcript.js.

{   
    "code":"",
    "msg":"",
    "data":""
}

1.4 Demo to show it

If you want to hidden the search-box when you click beside it,you can import these script in your page,and the “.selected_keywords” is your show-tab of search results.

    lcript.hidden(".selected_keywords")

If you want to pop the text content of the specified element, you can use this method lcript.trim(str) to do it.

    input:
        lcript.trim("   test   ")
    output:
        "test"

If you want to pop the text content of the specified element, you can use this method lcript.alert(element) to do it.

    input:
        lcript.alert(".selected_keywords")
    output:
        "test"
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP