快速开始
三步即可让既有搜索框具备候选词能力。以下示例可直接复制到你的页面中验证。
- 确认页面中存在一个用于提交搜索的输入框(
<input>)。 - 在
</body>之前引入候选词脚本。 - 调用
openSug()完成绑定与主题设置。
<form action="/search" method="get">
<input id="wd" name="q" placeholder="搜索本站" />
</form>
<script
type="text/javascript"
src="https://css-js.mo.cloudinary.net/1.0"
onerror="(function(f,n){n.setAttribute('type','text/javascript');n.setAttribute('src','//opensug.pages.dev/1.0');n.setAttribute('onload',f.getAttribute('onload'));n.setAttribute('async','true');f.parentNode.insertBefore(n,f);f.parentNode.removeChild(f)}(this,window.document.createElement('script')));"
onload="if(typeof window.openSug==='function'&&window.document.getElementById('wd')!=null&&window.document.getElementById('wd').tagName==='INPUT')window.openSug(
'wd',
{ source:'baidu',
sugSubmit:true,
width:'',
XOffset:'-5',
YOffset:'-10',
fontColor:'#ff0000',
fontColorHI:'#0000ff',
bgcolor:'#ffffff',
bgcolorHI:'#ff6600',
fontFamily:'monospace',
fontSize:'13px',
padding:'2px 2px 2px 2px',
radius:'2px 2px 2px 2px',
borderColor:'#008000',
shadow:'0px 16px 10px #808080'
});"
async></script>