首页 > IT职业 > IT图书 > lcript from carol
A simple script for HTML to do. https://carolcoral.github.io/Lcript/
[TOC]
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-->
<!--import bootstrap--> 2.Then you can import this script in your page to do Search.
<!--import search javascript-->
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.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.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 =
""
//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":""
}

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"
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/46/viewspace-2804609/ ,如需转载,请注明出处,否则将追究法律责任。