javascript 模糊搜索


<input type="text" οnkeyup="autoComplete(this,$('Entity_id'),$('Entity_id'),'text',false)" size="15" name="Input" id="Input"/>
      <SELECT NAME="Entity_id" id="Entity_id" >...</select>

<script>

function autoComplete(field, select_one,select_two, property, forcematch,copyflag) {
var select = select_one;
var found_one = false;
var found_two = false;
var selectedValue = null;
if(field.value.length==0) {return;}
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) >= 0) {
found_one=true; break;
}
}

if(!found_one){
select= select_two;
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) >= 0) {
found_two=true; break;
}
}
}

if(found_two){
selectedValue = select.options[i].value;
}

select=select_one;

if(found_two){
for(var j=0;j<select.options.length;j++){
if(select.options[j].value==selectedValue){
found_one=true;
i=j;
break;
}
}
}



if (found_one) { select_one.selectedIndex = i; }
else { select_one.selectedIndex = -1; }

if (field.createTextRange) {
if (forcematch && !found_one) {
field.value=field.value.substring(0,field.value.length-1); 
return;
}
var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";

if (cursorKeys.indexOf(event.keyCode+";") == -1) {
if (!copyflag) {
var r1 = field.createTextRange();
var oldValue = r1.text;
var newValue = found_one ? select_one.options[i][property] : oldValue;
if (newValue != field.value) {
//field.value = newValue;
var rNew = field.createTextRange();
rNew.moveStart('character', oldValue.length) ;
rNew.select();
}
}
}
}
}

</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值