html新浪搜索框,JS+CSS实现仿新浪微博搜索框的方法

这篇文章主要介绍了JS+CSS实现仿新浪微博搜索框的方法,实例分析了javascript针对搜索框样式的控制技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了JS+CSS实现仿新浪微博搜索框的方法。分享给大家供大家参考。具体实现方法如下:

JS+CSS仿类似新浪微博搜索框的效果

* { padding:0; margin:0;}

body { font-size:14px; }

#box { width:600px; margin:40px auto;}

#in { width:240px; height:24px; line-height:24px; border:1px solid #369; border-radius:4px; box-shadow:inset 0 0 2px #999; }

#suggest { display:none; position:relative; margin-top:-1px; width:240px; padding-top:1px; border:1px solid #369; border-top:0 none;

border-radius:4px; box-shadow:inset 0 0 2px #999; overflow:hidden; }

#suggest a { display:block; color:#f00; height:24px; line-height:24px; text-decoration:none; padding:0 4px;}

#suggest a:hover { background:#eee;}

#suggest a span { color#369;}

window.οnlοad=function(){

//声明一坨变量供下面使用

var obox=document.getElementById("box");

obj=document.getElementById("in");

osug=document.getElementById("suggest");

oa=osug.getElementsByTagName("span");

//兼容ie和火狐浏览器的方式,但是经测试发现ie678可以ie9却不行在删除的时候无法触发,网上查下说有ie9这个问题

obj.οninput=obj.onpropertychange=onchange;

function onchange(){

var txt=this.value;

var words=txt.length;

if(words==0){

osug.style.display="none";

}else if(words<=8){

osug.style.display="block";

for( var i=0;len=oa.length,i

oa[i].innerHTML=txt;

}

}else if(words>8){

osug.style.display="block";

var limit=txt.substring(0,8)+"...";

for( var i=0;len=oa.length,i

oa[i].innerHTML=limit;

}

}

}

}

function disbox(){

document.getElementById("suggest").style.display="none";

}

搜“”相关微博

搜“”相关用户

相关推荐下载:

以上就是本章的全部内容,更多相关教程请访问JavaScript视频教程!

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值