-
Notifications
You must be signed in to change notification settings - Fork 0
/
sou.js
47 lines (46 loc) · 1.7 KB
/
sou.js
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
//关键词sug
$(function() {
//当键盘键被松开时发送Ajax获取数据
$('#search-text').keyup(function() {
var keywords = $(this).val();
if (keywords == '') { $('#word').hide(); return };
$.ajax({
url: 'https://suggestion.baidu.com/su?wd=' + keywords,
dataType: 'jsonp',
jsonp: 'cb', //回调函数的参数名(键值)key
// jsonpCallback: 'fun', //回调函数名(值) value
beforeSend: function() {
// $('#word').append('<li>正在加载。。。</li>');
},
success: function(data) {
$('#word').empty().show();
if (data.s == '') {
//$('#word').append('<div class="error">Not find "' + keywords + '"</div>');
$('#word').empty();
$('#word').hide();
}
$.each(data.s, function() {
$('#word').append('<li>' + this + '</li>');
})
},
error: function() {
$('#word').empty().show();
//$('#word').append('<div class="click_work">Fail "' + keywords + '"</div>');
$('#word').hide();
}
})
})
//点击搜索数据复制给搜索框
$(document).on('click', '#word li', function() {
var word = $(this).text();
$('#search-text').val(word);
$('#word').empty();
$('#word').hide();
//$("form").submit();
$('.submit').trigger('click');//触发搜索事件
})
$(document).on('click', '.container,.banner-video,nav', function() {
$('#word').empty();
$('#word').hide();
})
})