码迷,mamicode.com
首页 > Web开发 > 详细

原生JS模拟百度搜索关键字与跳转

时间:2016-09-30 01:11:10      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

<style type="text/css">
*{
margin: 0;
padding: 0;
}
#text{
width: 300px;
height: 30px;
}
ul {
width: 302px;
border: 1px solid #ddd;
border-top:0;
display: none;
}
ul li {
list-style: none;
font-size: 12px;
font-family: "微软雅黑";
height: 20px;
line-height: 20px;
}
ul li a{
text-decoration: none;
color: #000;
display: block;
}
ul li a:hover{
background: red;
color: #fff;
}
</style>
</head>
<body>
<input type="text" id="text" />
<ul id="list"></ul>
<script type="text/javascript">
var oTxt = document.getElementById("text");
var oUl = document.getElementById("list");
oTxt.onkeyup = function(){
var val = oTxt.value;
var oScript = document.createElement(‘script‘);
oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+val+"&cb=hhl";
document.body.appendChild( oScript );
document.body.removeChild( oScript );
}
function hhl( data ){
var str = ‘‘;
for( var i=0;i<data.s.length;i++ ){
str += ‘<li><a href="https://www.baidu.com/s?wd=‘+data.s[i]+‘">‘+data.s[i]+‘</a></li>‘;
}
oUl.innerHTML = str;
oUl.style.display = ‘block‘;
}

</script>
</body>

原生JS模拟百度搜索关键字与跳转

标签:

原文地址:http://www.cnblogs.com/ypengbk/p/5921983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!