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>
    

      

  • 相关阅读:
    统计代码测试覆盖率-Python
    第一篇
    svn统计代码行数(增量)
    android多渠道打包
    解决Error:All flavors must now belong to a named flavor dimension. Learn more at...
    Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{...
    解决Android编译时出现aapt.exe finished with non-zero exit value 1
    自定义Json解析工具
    Process 'command 'D:jdk8jdkinjava.exe'' finished with non-zero exit value 2
    C:Program FilesJavajdk1.7.0_79injava.exe'' finished with non-zero exit value 1
  • 原文地址:https://www.cnblogs.com/mingjixiaohui/p/5246869.html
Copyright © 2011-2022 走看看