百度首页建议关键字的利用(JSONP)

本文介绍了一种利用百度建议API实现网页中关键字提示的方法。通过创建表单与按钮,结合特定JS文件,开发者能够轻松地为网站添加智能搜索建议功能。文章提供了完整的HTML示例代码及在线演示链接。

基本上百度建议关键字的利用方式如下:

1、在页面中新建一个form表单

2、表单中包含两个input元素,id必须固定:

<input type="text" id="kw">
<input type="button" id="su" value="搜索">

3、引入js文件,并启动:

<script type="text/javascript">var bds = {se:{},comm:{sid:"1461_1945_2202_1788_2250"}};</script>
<script type="text/javascript" src="http://s1.bdstatic.com/r/www/cache/global/js/home-2.10.js" charset="gbk"></script>
<script type="text/javascript">bds.se.sug();</script>

# 注意:上面的顺序不能改变!

4、在线演示,印象搜索:http://www.impress.pw/

5、完整html如下:

<!DOCTYPE html>
<html itemscope="" itemtype="http://schema.org/WebPage">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>百度建议关键字提示 ... </title>
</head>
<body> 
<form action="xxx">
	<input type="text" id="kw">
	<input type="button" id="su" value="搜索">
</form>
<script type="text/javascript">var bds = {se:{},comm:{sid:"1461_1945_2202_1788_2250"}};</script>
<script type="text/javascript" src="http://s1.bdstatic.com/r/www/cache/global/js/home-2.10.js" charset="gbk"></script>
<script type="text/javascript">bds.se.sug();</script>
</body>
</html>


Have Fun! 可以的话,记得点赞。



转载于:https://my.oschina.net/twinkling/blog/181670

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值