zoukankan      html  css  js  c++  java
  • ajax之百度 应用实例

    <input type="text" id="inp"/>
    		<ul id="wdList">
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    		</ul>
    

      

    <script type="text/javascript">
    //			https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=aa&cb=jQuery1102048553532222285867_1456368977799
    			var oInp = document.getElementById("inp");
    			var body = document.getElementsByTagName("body")[0];
    			var wdList = document.getElementById("wdList").getElementsByTagName("a");
    			window.onkeyup = function(){
    				createScript();
    			}
    			function createScript(){
    				var oScript = document.createElement("script");
    				oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+oInp.value+"&cb=jh";	
    				body.appendChild(oScript);
    				body.removeChild(oScript);
    			}
        //这里用参数接受回调函数 所有有形参json
    			function jh(json){
    				for(var i=0;i<wdList.length;i++){
    					wdList[i].innerHTML = json.s[i];
    					wdList[i].onclick = function(){
    						oInp.value = this.innerHTML;
    						console.log(oInp.value)
    						window.location.href = "https://www.baidu.com/s?wd="+oInp.value;
    						return false;
    					}
    				}
    			}
    		</script>
    

      借用百度的数据!

    自动创建 dom

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    	</head>
    	<body>
    		<input type="text" id="inp"/>
    		<ul id="wdList">
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    			<li><a href=""></a></li>
    		</ul>
    		<script type="text/javascript">
    //			https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=aa&cb=jQuery1102048553532222285867_1456368977799
    			var oInp = document.getElementById("inp");
    			var body = document.getElementsByTagName("body")[0];
    			var wdList = document.getElementById("wdList").getElementsByTagName("a");
    			window.onkeyup = function(){
    				createScript();
    			}
    			function createScript(){
    				var oScript = document.createElement("script");
    				oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+oInp.value+"&cb=syz";	
    				body.appendChild(oScript);
    				body.removeChild(oScript);
    			}
    			function syz(json){
    				for(var i=0;i<wdList.length;i++){
    					wdList[i].innerHTML = json.s[i];
    					wdList[i].onclick = function(){
    						oInp.value = this.innerHTML;
    						console.log(oInp.value)
    						window.location.href = "https://www.baidu.com/s?wd="+oInp.value;
    						return false;
    					}
    				}
    			}
    		</script>
    	</body>
    </html>
    

      

  • 相关阅读:
    poj 2187 Beauty Contest(旋转卡壳)
    poj 2540 Hotter Colder(极角计算半平面交)
    poj 1279 Art Gallery(利用极角计算半平面交)
    poj 3384 Feng Shui(半平面交的联机算法)
    poj 1151 Atlantis(矩形面积并)
    zoj 1659 Mobile Phone Coverage(矩形面积并)
    uva 10213 How Many Pieces of Land (欧拉公式计算多面体)
    uva 190 Circle Through Three Points(三点求外心)
    zoj 1280 Intersecting Lines(两直线交点)
    poj 1041 John's trip(欧拉回路)
  • 原文地址:https://www.cnblogs.com/mingjixiaohui/p/5246869.html
Copyright © 2011-2022 走看看