类似于百度搜索,搜索关键字,下拉框显示,以及jQuery中添加删除class类,并给class类添加样式






< script>
function getContent(obj){
       $( "#a" ).hide();
           $( "#b" ).hide();
           $( "#c" ).hide();
    var kw = jQuery.trim($(obj).val());
    if (kw == "" ){
        $( "#append" ).hide().html( "" );
        return false ;
    }
    var html = "" ;
   
    for ( var i = 0; i < data.length; i++) {
        if (data[i].indexOf(kw) >= 0) {
            html = html + "<div class='item' οnmοuseenter='getFocus(this)' onClick='getCon(this," +i+ ");' style='height:30px'>" + data[i] + "</div>"
 
        }
    }
    if (html != "" ){
        $( "#append" ).show().html(html);
    } else {
     searchUser();
        $( "#append" ).hide().html( "" );
    }
}

functiongetFocus(obj){
     
    $(".item").removeClass("addbg");
    $(obj).addClass("addbg");
}
/*想要鼠标经过搜索后的一条数据后,颜色变绿,但不能所有的   .item变绿,只让经过的一条变绿,所以要用jQuery添加class,然后在css
 * 中控制颜色,通过$(".item").removeClass("addbg"),搜索出来的所有的 .item都先把addbg的样式去掉,经过的那个当前的
 *obj(也就是getFocus(this)中的this)时,添加addbg的类
 */



</ script>


<  html >
<  body >
      < tr >
        < th > 客户信息: </ th >
        < td >
        < input   style =" margin-bottom : 0px " type = "text" name = "trueName" id = "trueName"                              onKeyup = "getContent(this);" value = "" maxlength = "40"
                placeholder = "输入客户姓名进行查找" />
                   
            < span id = "a" >< br >
               < input type = "text" name = "clientPhone" id = "clientPhone" value = "" maxlength = "40"                   placeholder = "输入客户姓名进行查找" disabled = "true" />
           </ span >
            < span id = "b" >< br >
               < input type = "text" name = " clientPhone" id = "clientEmail" value = "" maxlength = "40"                   placeholder = "输入客户姓名进行查找" disabled = "true" />
          </ span >
           < span id = "c" >< br >
                < input type = "text" name = "clientNickName" id = "clientNickName" value = ""                         maxlength = "40" placeholder = "输入客户姓名进行查找" disabled = "true" />
         </ span >

           < div id = "append" ></ div >
          </ td >
     </ tr >
</  body >
</  html >









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值