数码资讯
jsuggest自动匹配下拉框的使用方法(例如代码)
1。下载jquery-latest.js,jsuggest.js和JSuggest.css 的jsuggest.js源代码如下 复制代码代码如下所示: / * * * *说明:jsuggest下拉提示 * / 功能jsuggest(){ 下拉框 this.div = null; UL/div thi
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
1。下载jquery-latest.js,jsuggest.js和JSuggest.css
的jsuggest.js源代码如下
复制代码代码如下所示:
/ * *
*
*说明:jsuggest下拉提示
* /
功能jsuggest(){
下拉框
this.div = null;
UL/div
this.ul = null;
文本输入框
this.input = null;
选择的对象
this.current_li = null;
*隐藏下拉提示
* /
this.hide =函数(){
this.div.style.visibility =隐藏;
}
*显示下拉提示符
* /
这。=函数(){
this.div.style.visibility =可见;
}
/ * *
*下拉提示框状态
* /
this.status =函数(){
如果(this.div.style.visibility = =可见){
返回true;
}
返回false;
}
*设置当前div选择的LI
* /
this.setcurrent_li =函数(李,obj){
协= obj.current_li;
如果(co)!= NULL){
co.classname = ;
}
li.classname =li_index ;
obj.current_li =李;
}
*建议的初始化
*
* input_id:在输入框的ID
* defheight:下拉提示框高(不可提供)
* /
this.init =功能(input_id,defheight){
this.input = document.getelementbyid(input_id);
/ / this.input.autocomplete =关闭;
左= this.input.offsetleft VaR;
var = this.input.offsettop;
VaR的宽度= this.input.offsetwidth;
VaR高度= this.input.offsetheight;
var p = this.input.offsetparent;
而(P!= NULL){
左+ = p.offsetleft;
顶+ = p.offsettop;
P = p.offsetparent;
}
顶部+高度;
如果(defheight = = null | | defheight = = 0){
高度= 150;
其他{ }
高度= defheight;
}
this.input.value = ;
var obj =这;
this.input.onkeydown =功能(EVT){
obj.onkeydown(EVT,obj);
}
this.div = document.createelement(div);
this.div.style.width =宽+PX;
this.div.style.height =高度+PX;
this.div.style.left =左+PX;
this.div.style.top = +PX;
this.ul = document.createelement(UL);
(这this.div.appendchild。UL);
this.div.classname =jsuggest ;
document.body.appendchild(这个div);
}
*在div下删除UL中的所有LI
* /
this.remove =函数(){
this.current_li = null;
而(this.removeli());
}
/ * *
*在div下删除UL中的李
* /
this.removeli =函数(){
var node = this.ul.childnodes;
对于(节点中的var){
如果(节点{ }!= null节点{ }形式= =){李。
/ /警报(结{ }。innerHTML);
this.ul.removechild(结{ });
返回true;
}
}
返回false;
}
/ * *
*在div中创建
* /
this.create =功能(项目){
This.remove();
无功li_item = items.split(
对于(VAR我li_item){
/ /警报(li_item {我});
Var Li = document.createelement(礼);
li.innerhtml = li_item {我};
var obj =这;
li.onmousedown =函数(){
Obj.onmousedown(这个目标);
}
li.onmouseover = this.onmouseover;
li.onmouseout = this.onmouseout;
this.ul.appendchild(李);
}
This.show();
}
/ * *
*文本框新闻事件
* /
this.onkeydown =功能(EVT,obj){
如果(!obj.status()){
返回false;
}
如果(!EVT窗口事件)。
{
EVT = window.event;
}
var关键字= evt.keycode;
/ / var KeyUp = 38;
/ / var keydown = 40;
/ /无功keyenter = 13;
var obj OB =;
如果(键= 38){
obj.upkeyselected();
}如果(键= 40){
obj.downkeyselected();
} else if(关键= = 13 | | {关键= = 27)
Obj.hide();
}
}
this.getcurrentliindex =函数(){
如果(this.current_li = = null){
返回- 1;
}
var node = this.ul.childnodes;
对于(节点中的var){
如果(结{ } = =。nodename李){
如果(节点{N} = =这。current_li){
返回N;
}
}
}
}
this.getli =函数(指数){
var node = this.ul.childnodes;
对于(节点中的var){
如果(结{ } = =。它们李n = =指数){
this.setcurrent_li(结{ },这个);
返回节点{ };
}
}
}
this.upkeyselected =函数(){
VaR Num = this.getcurrentliindex();
如果(Num)!= 1个数字> 0){
Num --;
var node = this.getli(努姆);
this.setcurrent_li(节点,这个);
this.input.value = node.innerhtml;
}
}
this.downkeyselected =功能(obj){
VaR Num = this.getcurrentliindex();
如果(数字= 1){
数字= 0;
{ }人
数字+;
如果返回false(民数记> =这。UL。子。长度);
}
var node = this.getli(努姆);
this.setcurrent_li(节点,这个);
this.input.value = node.innerhtml;
}
/ * *
*鼠标按下事件
* /
This.onmousedown = function (thiz, obj) {
obj.setcurrent_li(即时,obj);
obj.input.value = thiz.innerhtml;
Obj.hide();
}
*鼠标移动事件
* /
this.onmouseover =函数(){
如果(this.classname!=li_index ){
this.classname =li_check ;
}
}
*鼠标移出事件
* /
this.onmouseout =函数(){
如果(this.classname = = li_check){
this.classname = ;
}
}
}
无功jsuggest =新jsuggest();
2.jsp页
复制代码代码如下所示:
j(文档)Ready(函数()){
/ /初始化jsuggest
Jsuggest.init(文本);
/ /或使用设置下拉框高度的方法
/ / jsuggest.init(文本
})
函数go(事件,值){
事件=事件:(window.event window.event:论点{ 0 });
var url =urlsuggestinput =+ encodeURIComponent(价值); / / URL是一个特定的动作或JSP地址,返回值是一个逗号分隔的字符串
gosuggestinput(事件、URL、价值);
}
功能gosuggestinput(事件、URL值){
如果(值= ={)
如果输入框是空的隐藏下拉框
Jsuggest.hide();
返回false;
}
/ /确保EVT是有效的事件
如果(!事件窗口的事件)。
{
事件= window.event;
}
var关键字= evnet.keycode;
如果(关键= = 38 = = 40 = =关键| | | | 13 | | {关键= = 27)
返回false;
}
j.ajax({
类型:邮政
网址,
DataType:文本
缓存:false
beforesend:功能(XMLHttpRequest){
},
成功:功能(数据,textstatus){
添加一个下拉框数据
jsuggest.create(数据);
},
完成:功能(XMLHttpRequest,textstatus){
},
错误:函数(){
警告(抱歉),服务器忙!;
}
});
}
的jsuggest.js源代码如下
复制代码代码如下所示:
/ * *
*
*说明:jsuggest下拉提示
* /
功能jsuggest(){
下拉框
this.div = null;
UL/div
this.ul = null;
文本输入框
this.input = null;
选择的对象
this.current_li = null;
*隐藏下拉提示
* /
this.hide =函数(){
this.div.style.visibility =隐藏;
}
*显示下拉提示符
* /
这。=函数(){
this.div.style.visibility =可见;
}
/ * *
*下拉提示框状态
* /
this.status =函数(){
如果(this.div.style.visibility = =可见){
返回true;
}
返回false;
}
*设置当前div选择的LI
* /
this.setcurrent_li =函数(李,obj){
协= obj.current_li;
如果(co)!= NULL){
co.classname = ;
}
li.classname =li_index ;
obj.current_li =李;
}
*建议的初始化
*
* input_id:在输入框的ID
* defheight:下拉提示框高(不可提供)
* /
this.init =功能(input_id,defheight){
this.input = document.getelementbyid(input_id);
/ / this.input.autocomplete =关闭;
左= this.input.offsetleft VaR;
var = this.input.offsettop;
VaR的宽度= this.input.offsetwidth;
VaR高度= this.input.offsetheight;
var p = this.input.offsetparent;
而(P!= NULL){
左+ = p.offsetleft;
顶+ = p.offsettop;
P = p.offsetparent;
}
顶部+高度;
如果(defheight = = null | | defheight = = 0){
高度= 150;
其他{ }
高度= defheight;
}
this.input.value = ;
var obj =这;
this.input.onkeydown =功能(EVT){
obj.onkeydown(EVT,obj);
}
this.div = document.createelement(div);
this.div.style.width =宽+PX;
this.div.style.height =高度+PX;
this.div.style.left =左+PX;
this.div.style.top = +PX;
this.ul = document.createelement(UL);
(这this.div.appendchild。UL);
this.div.classname =jsuggest ;
document.body.appendchild(这个div);
}
*在div下删除UL中的所有LI
* /
this.remove =函数(){
this.current_li = null;
而(this.removeli());
}
/ * *
*在div下删除UL中的李
* /
this.removeli =函数(){
var node = this.ul.childnodes;
对于(节点中的var){
如果(节点{ }!= null节点{ }形式= =){李。
/ /警报(结{ }。innerHTML);
this.ul.removechild(结{ });
返回true;
}
}
返回false;
}
/ * *
*在div中创建
* /
this.create =功能(项目){
This.remove();
无功li_item = items.split(
对于(VAR我li_item){
/ /警报(li_item {我});
Var Li = document.createelement(礼);
li.innerhtml = li_item {我};
var obj =这;
li.onmousedown =函数(){
Obj.onmousedown(这个目标);
}
li.onmouseover = this.onmouseover;
li.onmouseout = this.onmouseout;
this.ul.appendchild(李);
}
This.show();
}
/ * *
*文本框新闻事件
* /
this.onkeydown =功能(EVT,obj){
如果(!obj.status()){
返回false;
}
如果(!EVT窗口事件)。
{
EVT = window.event;
}
var关键字= evt.keycode;
/ / var KeyUp = 38;
/ / var keydown = 40;
/ /无功keyenter = 13;
var obj OB =;
如果(键= 38){
obj.upkeyselected();
}如果(键= 40){
obj.downkeyselected();
} else if(关键= = 13 | | {关键= = 27)
Obj.hide();
}
}
this.getcurrentliindex =函数(){
如果(this.current_li = = null){
返回- 1;
}
var node = this.ul.childnodes;
对于(节点中的var){
如果(结{ } = =。nodename李){
如果(节点{N} = =这。current_li){
返回N;
}
}
}
}
this.getli =函数(指数){
var node = this.ul.childnodes;
对于(节点中的var){
如果(结{ } = =。它们李n = =指数){
this.setcurrent_li(结{ },这个);
返回节点{ };
}
}
}
this.upkeyselected =函数(){
VaR Num = this.getcurrentliindex();
如果(Num)!= 1个数字> 0){
Num --;
var node = this.getli(努姆);
this.setcurrent_li(节点,这个);
this.input.value = node.innerhtml;
}
}
this.downkeyselected =功能(obj){
VaR Num = this.getcurrentliindex();
如果(数字= 1){
数字= 0;
{ }人
数字+;
如果返回false(民数记> =这。UL。子。长度);
}
var node = this.getli(努姆);
this.setcurrent_li(节点,这个);
this.input.value = node.innerhtml;
}
/ * *
*鼠标按下事件
* /
This.onmousedown = function (thiz, obj) {
obj.setcurrent_li(即时,obj);
obj.input.value = thiz.innerhtml;
Obj.hide();
}
*鼠标移动事件
* /
this.onmouseover =函数(){
如果(this.classname!=li_index ){
this.classname =li_check ;
}
}
*鼠标移出事件
* /
this.onmouseout =函数(){
如果(this.classname = = li_check){
this.classname = ;
}
}
}
无功jsuggest =新jsuggest();
2.jsp页
复制代码代码如下所示:
j(文档)Ready(函数()){
/ /初始化jsuggest
Jsuggest.init(文本);
/ /或使用设置下拉框高度的方法
/ / jsuggest.init(文本
})
函数go(事件,值){
事件=事件:(window.event window.event:论点{ 0 });
var url =urlsuggestinput =+ encodeURIComponent(价值); / / URL是一个特定的动作或JSP地址,返回值是一个逗号分隔的字符串
gosuggestinput(事件、URL、价值);
}
功能gosuggestinput(事件、URL值){
如果(值= ={)
如果输入框是空的隐藏下拉框
Jsuggest.hide();
返回false;
}
/ /确保EVT是有效的事件
如果(!事件窗口的事件)。
{
事件= window.event;
}
var关键字= evnet.keycode;
如果(关键= = 38 = = 40 = =关键| | | | 13 | | {关键= = 27)
返回false;
}
j.ajax({
类型:邮政
网址,
DataType:文本
缓存:false
beforesend:功能(XMLHttpRequest){
},
成功:功能(数据,textstatus){
添加一个下拉框数据
jsuggest.create(数据);
},
完成:功能(XMLHttpRequest,textstatus){
},
错误:函数(){
警告(抱歉),服务器忙!;
}
});
}
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。