效果图如下

yV1nGq.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>百度搜索API</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.wrap{
margin: 100px auto;
width: 600px;
height: 50px;
}
#inputword{
width: 500px;
height: 100%;
display: block;
float: left;
}
#search{
width: 90px;
height: 100%;
display: block;
}
.show{
}
</style>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div class="wrap">
<form action="http://www.baidu.com" target="_blank">
<input type="text" id="inputword" />
<input type="submit" name="search" id="search" value=" 搜索" />
</form>
</div>
<p class="show">
</p>

<script type="text/javascript">
// http://suggestion.baidu.com/su?wd=#content#&cb=window.baidu.sug
$(function(){
// var url ="http://suggestion.baidu.com/su?wd=#content#&cb=window.baidu.sug";

$("#inputword").keyup(function(){
var content=$("#inputword").val();
$.ajax({
type:"GET",
url:"http://suggestion.baidu.com/su?wd="+content,
dataType:"jsonp",
jsonp:"cb",
success:function(data){
var json =data.s;
var html ="";
for (var i = 0; i < json.length; i++) {
html+="<li>"+json[i]+"<li>";
}
$(".show").html(html);
}
});
})
})
$("#search").click(function(){
window.open("https://www.baidu.com/s?&wd="+$("#inputword").val());
})
</script>
</body>
</html>