<!--
JSONP由回調(diào)函數(shù)和數(shù)據(jù)組成
通過查詢字符串指定當(dāng)響應(yīng)到來時(shí)在頁面中調(diào)用的函數(shù)
可以直接訪問響應(yīng)文本,實(shí)現(xiàn)雙向通信,不過無法保證響應(yīng)內(nèi)容的安全性
-->
<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>跨域--jsonp--百度搜索</title>
<style?type="text/css">
????html,body,div,input,ul,li,a{
????margin:?0;
????padding:?0;
????}
????
????#baiduSearch{
????position:?absolute;
????top:?10px;
????}
????
????#baiduSearch{
????left:?100px;
????}
????
????#baiduSearch?input{
????????width:?300px;
????????height:?30px;
????????padding:?5px;
????????border:?1px?solid?#F90;
????????font-size:?16px;
????}
????
????#baiduSearch?ul{
????????display:?none;
????????width:?310px;
????????border:?1px?solid?#F90;
????}
????
????#baiduSearch?li{
????????list-style:?none;
????}
????
????#baiduSearch?li?a{
????????padding:?5px;
????????text-decoration:?none;
????????line-height:?30px;
????????color:?#000;
????}
????
????#baiduSearch?li?a:hover{
????????display:?block;
????????color:?#FFF;
????????background-color:?#F90;
????}
</style>
</head>
<body>
????<div?id="baiduSearch">
????????<input?type="text"?value=""?name="q"?placeholder="百度搜索">
????????<ul></ul>
????</div>
<script?type="text/javascript">
????var?oBaidu?=?document.getElementById("baiduSearch");
????var?baiduSearch?=?oBaidu.getElementsByTagName("input")[0];
????var?baiduList?=?oBaidu.getElementsByTagName("ul")[0];
????
????function?baiduSug(data)?{
????????var?html?=?"";
????????
????????if?(data.s.length)?{
????????????baiduList.style.display?=?"block";
????????????for?(var?i=0;?i<data.s.length;?i++)?{
????????????????html?+=?"<li><a?target='_blank'?;
????????????};
????????????baiduList.innerHTML?=?html;
????????}?else?{
????????????baiduList.style.display?=?"none";
????????};
????}
????
????baiduSearch.onkeyup?=?function?()?{
????????if?(this.value?!=?"")?{
????????????var?oScript?=?document.createElement("script");
????????????oScript.src?=?"http://suggestion.baidu.com/su?cb=baiduSug&wd="+this.value;
????????????if?(document.body)?{
????????????????document.body.appendChild(oScript);
????????????}?else?{
????????????????document.documentElement.appendChild(oScript);
????????????};
????????}?else?{
????????????baiduList.style.display?=?"none";
????????};
????}
</script>
</body>
</html>
</body>
</html>
2017-03-05
$_GET[cb].'({jsondata})'
2017-03-05
oScript.src?=?"http://suggestion.baidu.com/su?cb=baiduSug&wd="+this.value;
在后臺(tái)是如何處理cb=baiduSug?來實(shí)現(xiàn)調(diào)用js baiduSug這個(gè)函數(shù)的?
2016-12-29
在Java端,我的返回值格式是怎么樣的?
2016-11-07
本來以為是問題,結(jié)果我把代碼看了一遍后,發(fā)現(xiàn)你理解的這么透徹,反而自己受益匪淺呀!