Search and paging effect implemented by jquery + json _ jquery

Source: Internet
Author: User
Javascript, json-implemented js script search, add pagination, with source code 1.Web contains three directories:
1.1 content.htm // run the file directly.
1.2 js // Several js files useful here, where the data source starting with db (that is, the json string)
1.3 css // css.
2. Run content.htm directly to view the page and search results.
3. The principle is very simple, but the index function of javascript is used.
Core code:

The Code is as follows:


/*
Author: liulf
Function:
Var _ db_cpcj = vCpcj;
Var _ db_cp = vCp;
Var vCp = {"cppage ":[
{"Cpdh": "A01000101", "page": "1", "ca": "1309-36-0", "mc": "", "ename": "Pyrite", "bm":" "},
{"Cpdh": "A01000201", "page": "1", "ca": "1309-36-0", "mc": "Sulfur Concentrate ", "ename": "Pyrite concentrate; Sulfur concentrate", "bm ":""},
{"Cpdh": "A01000202", "page": "1", "ca": "1309-36-0", "mc": "Sulfur Concentrate Powder ", "ename": "Powdered pyrite concentrate; Pyrites concentrate, powder; Sulfur concentrate, powder", "bm": "Sulfur concentrate "},
{"Cpdh": "A02000101", "page": "1", "ca": "", "mc": "phosphate ore", "ename ": "Phosphorus ore", "bm ":""},
{"Cpdh": "A02000111", "page": "2", "ca": "", "mc": "phosphate ore", "ename ": "Phosphorite grit", "bm ":""},
{"Cpdh": "A02000201", "page": "2", "ca": "", "mc": "phosphate rock powder", "ename ": "Phosphate rock powder", "bm ":""},
{"Cpdh": "A03000101", "page": "2", "ca": "12447-04-0", "mc": "Boron Ore ", "ename": "Ascharite; Boric ore", "bm": "Boron and magnesium "},
{"Cpdh": "A04000101", "page": "2", "ca": "", "mc": "Potash", "ename": "Potash feldspar; potassium feldspars "," bm ":""},
{"Cpdh": "A04000201", "page": "2", "ca": "12003-63-3", "mc": "Long powder ", "ename": "Feldspar powder", "bm ":""},
{"Cpdh": "A04000301", "page": "2", "ca": "", "mc": "Halogen Stone", "ename": "Carnallite ", "bm ":""}
]}
Var vCpcj = {"cjpage": [{"cjdh": "110634", "cm": "Bayer Optical Fiber Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110052", "cm": "Beijing Iris ink Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110408", "cm": "Beijing aisk Pharmaceutical Technology Development Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110010", "cm": "Beijing edutepe membrane factory", "pagen": "1701 "},
{"Cjdh": "110165", "cm": "Beijing Anshi Technology Development Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110134", "cm": "Beijing anshunda decorative materials Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110291", "cm": "Beijing Obo star biotechnology Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110191", "cm": "Beijing Otis Chemical Co. Ltd.", "pagen": "1701 "},
{"Cjdh": "110454", "cm": "Beijing Auckland Waterproof Engineering Co., Ltd.", "pagen": "1701 "},
{"Cjdh": "110520", "cm": "Beijing aosen special lubricating Material Factory", "pagen": "1701"}]}
Ocent
*/
Function ObjSearch ()
{
This. kw = '';
This. option = '';
This. displayId = '';
This. search = function ()
{
// If (this. kw = ''| this. kw = null | this. kw. length <3)
//{
// Alert ('the input length cannot be less than 3! ');
// Return;
//}
// Switch (this. option)
//{
//// Enterprise
// Case '0 ':
// This. searchCpcj ();
// Break;
/// Product
// Case '1 ':
// This. searchCp ();
// Break;
//}
OutputHtml (this );
}
This. searchCpcj = function ()
{
Var jsonObj = new Array ();
Var kw = this. kw;
// ('{'{This.displayid}.html ('');
// Var displayId = this. displayId;
$ (VCpcj. cjpage). each (function (index, content ){
// Var cjdhy = content. cjdh;
// Var cm = content. cm;
// Var pagen = content. pagen;
If (content. cm. indexOf (kw )! =-1)
{
// $ ('#' + DisplayId). append ("" + cm + "|" + pagen +"
");
JsonObj. push ({"cm": content. cm, "pagen": content. pagen });
}
});
Return jsonObj;
}
This. searchCp = function ()
{
Var jsonObj = new Array ();
Var kw = this. kw;
// ('{'{This.displayid}.html ('');
// Var displayId = this. displayId;
$. Each (vCp. cppage, function (index, content ){
// Var cpdh = content. cpdh;
// Var page = content. page;
// Var ca = content. ca;
// Var mc = content. mc;
// Var ename = content. ename;
// Var bm = content. bm;
If (content. mc. indexOf (kw )! =-1)
{
// $ ('#' + DisplayId). append ("" + mc + "|" + page +"
");
JsonObj. push ({"mc": content. mc, "page": content. page });
}
});
Return jsonObj;
}
}



Package
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.