jQuery Jsonp跨域模拟搜索引擎


Posted in jQuery onJune 17, 2017

效果还不错 就差加上键盘控制了...

jQuery Jsonp跨域模拟搜索引擎

代码如下:

<!DOCTYPE html> 
<html> 
  <head> 
    <meta charset="utf-8" /> 
    <title>迷糊网罗</title> 
    <style type="text/css"> 
      * { 
        margin: 0; 
        padding: 0; 
      } 
      form { 
        position: absolute; 
        left: 50%; 
        top: 40%; 
      } 
      form input:nth-child(1) { 
        width: 450px; 
        height: 34px; 
        float: left; 
        font-size: 16px; 
        text-indent: 0.5em; 
        outline: none; 
        box-sizing: border-box; 
      } 
      form input:nth-child(1):focus { 
        border: 1px solid blueviolet; 
      } 
      form input:nth-child(2) { 
        height: 34px; 
        float: left; 
        background: blueviolet; 
        cursor: pointer; 
        width: 80px; 
        letter-spacing: 2px; 
        border: 0; 
        font-size: 14px; 
        line-height: 34px; 
      } 
      #oul { 
        position: absolute; 
        left: 0; 
        top: 34px; 
        background: white; 
        width: 530px; 
        box-shadow: 3px 3px 5px #F3F3F3; 
        border: 1px solid #F3F3F3; 
        box-sizing: border-box; 
        display: none; 
      } 
      #oul li:hover { 
        background: #F3F3F3; 
        cursor: pointer; 
      } 
    </style> 
  </head> 
  <body> 
    <form action="" method="" name="ss"> 
      <input type="" name="ss" id="txt" value="" /> 
      <input type="button" name="ss" id="btn" value="迷糊网罗" /> 
      <ul id="oul"> 
      </ul> 
    </form> 
    <script type="text/javascript"> 
      //https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=&cb=&_=1497256697565 
      //位置调整 习惯就好.. 
      var fm = document.getElementsByTagName('form')[0]; 
      var x = fm.offsetWidth; 
      var y = fm.offsetHeight; 
      fm.style.marginLeft = -x / 2 + 'px'; 
      fm.style.marginTop = -y / 2 + 'px'; 
      //获取操作元素 
      var txt = document.getElementById("txt"); 
      var oul = document.getElementById("oul"); 
      //动态创建js脚本 
      txt.onkeyup = function(ev) { 
        var value = this.value; 
        var newscript = document.createElement("script"); 
        newscript.src = 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + value + '&cb=walk&_=' + Math.random(); 
        newscript.type = 'text/javascript'; 
        document.body.appendChild(newscript); 
      } 
      //设置回调函数 
      function walk(walkJson) { 
        if(txt.value == 0) { 
          oul.style.display = 'none'; 
        } else { 
          oul.style.display = 'block'; 
          oul.innerHTML = ''; 
          if(walkJson.s.length <= 10) { 
            for(var i = 0; i < walkJson.s.length; i++) { 
              var oli = document.createElement('li'); 
              oli.style.height = 25 + 'px'; 
              oli.style.width = 100 + '%'; 
              oli.style.lineHeight = 25 + 'px'; 
              oli.style.textIndent = 9 + 'px'; 
              oli.style.listStyle = 'none'; 
              oli.innerHTML = walkJson.s[i]; 
              oul.appendChild(oli); 
            } 
          } else { 
            for(var i = 0; i < 10; i++) { 
              var oli = document.createElement('li'); 
              oli.style.height = 25 + 'px'; 
              oli.style.width = 100 + '%'; 
              oli.style.lineHeight = 25 + 'px'; 
              oli.style.textIndent = 9 + 'px'; 
              oli.style.listStyle = 'none'; 
              oli.innerHTML = walkJson.s[i]; 
              oul.appendChild(oli); 
            } 
          } 
        } 
      } 
    </script> 
  </body> 
</html>

以上所述是小编给大家介绍的jQuery Jsonp跨域模拟搜索引擎的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

jQuery 相关文章推荐
jQuery中clone()函数实现表单中增加和减少输入项
May 13 jQuery
jQuery常用选择器详解
Jul 17 jQuery
jQuery实现带右侧索引功能的通讯录示例【附源码下载】
Apr 17 jQuery
jQuery中的$是什么意思及 $. 和 $().的区别
Apr 20 jQuery
jQuery实现列表的增加和删除功能
Jun 14 jQuery
jQuery插件实现弹性运动完整示例
Jul 07 jQuery
使用jQuery给Table动态增加行、清空table的方法
Sep 05 jQuery
详解jQuery设置内容和属性
Apr 11 jQuery
使用异步controller与jQuery实现卷帘式分页
Jun 18 jQuery
jquery插件开发模式实例详解
Jul 20 jQuery
jquery实现掷骰子小游戏
Oct 24 jQuery
JQuery使用数组遍历跳出each循环
Sep 01 jQuery
jQuery 控制文本框自动缩小字体填充
Jun 16 #jQuery
jQuery序列化后的表单值转换成Json
Jun 16 #jQuery
基于jQuery和CSS3实现APPLE TV海报视差效果
Jun 16 #jQuery
利用jquery去掉时光轴头尾部线条的方法实例
Jun 16 #jQuery
jQuery实现 RadioButton做必选校验功能
Jun 15 #jQuery
jQuery ajax动态生成table功能示例
Jun 14 #jQuery
jQuery.form.js的使用详解
Jun 14 #jQuery
You might like
PHP根据传来的16进制颜色代码自动改变背景颜色
2014/06/13 PHP
php中preg_match的isU代表什么意思
2015/10/01 PHP
JQuery获取文本框中字符长度的代码
2011/09/29 Javascript
jQuery Pagination Ajax分页插件(分页切换时无刷新与延迟)中文翻译版
2013/01/11 Javascript
jQuery中nextUntil()方法用法实例
2015/01/07 Javascript
JavaScript跨浏览器获取页面中相同class节点的方法
2015/03/03 Javascript
jquery实现通用的内容渐显Tab选项卡效果
2015/09/07 Javascript
js密码强度检测
2016/01/07 Javascript
AngularJS实现动态编译添加到dom中的方法
2016/11/04 Javascript
jQuery实现两个select控件的互移操作
2016/12/22 Javascript
DWR3 访问WEB元素的两种方法实例详解
2017/01/03 Javascript
解决vuecli3.0热更新失效的问题
2018/09/19 Javascript
jQuery动态生成的元素绑定事件操作实例分析
2019/05/04 jQuery
微信小程序实现列表的横向滑动方式
2020/07/15 Javascript
jquery实现加载更多&quot;转圈圈&quot;效果(示例代码)
2020/11/09 jQuery
[48:00]EG vs LGD 2018国际邀请赛淘汰赛BO3 第二场 8.26
2018/08/29 DOTA
[01:03:41]DOTA2-DPC中国联赛 正赛 Dynasty vs XG BO3 第三场 2月2日
2021/03/11 DOTA
Python循环语句之break与continue的用法
2015/10/14 Python
Python中使用Queue和Condition进行线程同步的方法
2016/01/19 Python
itchat和matplotlib的结合使用爬取微信信息的实例
2017/08/25 Python
python实现RabbitMQ的消息队列的示例代码
2018/11/08 Python
python对于requests的封装方法详解
2019/01/03 Python
提升Python程序性能的7个习惯
2019/04/14 Python
python调用私有属性的方法总结
2020/07/24 Python
基于Python的接口自动化读写excel文件的方法
2021/01/15 Python
HTML文本属性&amp;颜色控制属性的实现
2019/12/17 HTML / CSS
美国首屈一指的礼品篮供应商:GiftTree
2018/01/06 全球购物
英文版餐饮业求职信
2013/10/18 职场文书
中学生班主任评语
2014/01/30 职场文书
2014年两会学习心得范例
2014/03/17 职场文书
交通事故委托书范本(2篇)
2014/09/21 职场文书
介绍信样本
2015/01/31 职场文书
三严三实学习心得体会(精选N篇)
2016/01/05 职场文书
Python爬虫之爬取哔哩哔哩热门视频排行榜
2021/04/28 Python
Springboot配置suffix指定mvc视图的后缀方法
2021/07/03 Java/Android
MySQL RC事务隔离的实现
2022/03/31 MySQL