百度搜索提示框js代码

1、普通用法

<html>
<head> 
<meta http-equiv="X-UA-Compatible" content="IE=7"> 
<meta http-equiv="content-type" content="text/html;charset=gb2312"> 
<title>百度搜索提示框代码</title> 
</head> 
<body> 
<!-- 百度搜索框 --> 
<div> 
<form action="http://www.baidu.com/baidu" target="_blank"> 


<input type=text size=50  name=word baiduSug=1> 

<input type=text  name=word baiduSug=2>

<input type=submit value='baidu'

</form> 
 
</div> 
</body> 
<!-- 百度搜索框提示 --> 
<script charset="gbk" src="http://www.baidu.com/js/opensug.js"></script> 
</html> 

 

2、高级用法

<html><head> 
<meta http-equiv="X-UA-Compatible" content="IE=7"> 
<meta http-equiv="content-type" content="text/html;charset=gb2312"> 
<title>百度搜索提示框代码</title> 
<style> 
p{font-size:13px;line-height:2}
</style> 
</head> 
<body> 
 
<!-- 准备通过程序动态添加提示功能的input  --> 
<p> 
您的输入框:<input id="ipt1" type="text" style="width:200px;padding:1px;border:1px solid gray"> 
 
当前选择文字:<span id="alertSpan" style="font-weight:bold"></span> 
</p> 
</body> 
 
<!-- 百度搜索框提示 --> 
<script charset="gbk" src="http://www.baidu.com/js/opensug.js"></script> 
 
<!-- 程序示例  --> 
    
<script type="text/javascript"> 
     var txtObj = document.getElementById("alertSpan");
 
    //回调函数,用于获取用户当前选择的文字
     function show(str){
        txtObj.innerHTML = str;
    }
 
    var params = {
    "XOffset":0, //提示框位置横向偏移量,单位px
    "YOffset":0, //提示框位置纵向偏移量,单位px
    "width":204, //提示框宽度,单位px
    "fontColor":"#f70", //提示框文字颜色
    "fontColorHI":"#FFF",    //提示框高亮选择时文字颜色
    "fontSize":"12px",        //文字大小
    "fontFamily":"宋体",    //文字字体
    "borderColor":"gray",     //提示框的边框颜色
    "bgcolorHI":"#03c",        //提示框高亮选择的颜色
    "sugSubmit":false        //在选择提示词条是是否提交表单
    };
 
     BaiduSuggestion.bind("ipt1",params,show);
    
</script> 
</html> 

 

posted @ 2020-09-03 08:52  泛目录  阅读(471)  评论(0)    收藏  举报
泛目录程序