百度跨域搜索demo
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了百度跨域搜索demo相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
padding: 0;
margin: 0
}
.sousuo {
width: 300px;
height: 40px;
position: absolute;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
li {
list-style: none;
line-height: 30px;
padding: 0 10px;
}
li:hover {
background-color: #777;
color: #fff;
}
ul {
position: absolute;
display: none;
}
</style>
</head>
<body>
<input type="text" class="sousuo"/>
<ul class="ul"></ul>
<script src="../blog/javascripts/jquery-1.7.2.min.js"></script>
<script>
function position() {
var sousuo = $(".sousuo");
$(".ul").css({
top: sousuo.offset().top + sousuo.height() + 5,
left: sousuo.offset().left,
width: sousuo.css("width")
})
}
function demo(data) {
var ul = $(‘.ul‘);
var html = ‘‘;
if (data.s.length) {
ul.css("display",‘block‘);
for (var i = 0; i<data.s.length; i++) {
html +=‘<li>‘+data.s[i]+‘</li>‘;
}
ul.html(html);
}
}
$(".ul").delegate("li",‘click‘,function () {
location.href = ‘https://www.baidu.com/s?wd=‘+$(this).text();
});
$(document).ready(function () {
position();
$(‘.sousuo‘).on(‘keyup‘, function () {
if (this.value) {
var script = document.createElement("script");
script.src = ‘https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=‘+this.value+‘&cb=demo‘;
document.body.appendChild(script);
}
});
});
window.onresize = function () {
position();
}
</script>
</body>
</html>
以上是关于百度跨域搜索demo的主要内容,如果未能解决你的问题,请参考以下文章