<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>liangduanqi</title>
<style>
.gray{
background: #ccc;
}
</style>
<script src="vue.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/0.7.0/vue-resource.js"></script> </head>
<body>
<div id="box">
<input type="text" v-model='t1' @keyup="get($event)" @keydown.down="changeDown()" @keydown.up.prevent="changeUp()">
{{t1}}
<ul>
<li v-for="v in myData" :class="{gray:$index==now}">{{v}}</li> </ul>
<p v-show="myData.length==0">暂无数据。。。</p>
</div>
</body>
<script> new Vue({
el:'#box',
data:{
myData:[],
t1:'',
now:-1
},
methods:{
get:function (ev) {
if(ev.keyCode==38 || ev.keyCode==40)return; if(ev.keyCode==13){
window.open('https://www.baidu.com/s?wd='+this.t1);
this.t1='';
}
this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{
wd:this.t1
},{
jsonp:'cb'
}).then(function (res) {
this.myData=res.data.s;
},function () { }); },
changeDown:function () {
this.now++;
console.log(this.now,'Down');
if(this.now==this.myData.length)this.now=-1
this.t1=this.myData[this.now]; },
changeUp:function () {
this.now--;
if(this.now==-2)this.now=this.myData.length-1
this.t1=this.myData[this.now]; } }
}) </script>
</html>

利用api模拟百度搜索功能的更多相关文章

  1. JavaScript-dom3 json_str dom元素控制 模拟百度搜索

    访问关系-封装代码 html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  2. python--selenium简单模拟百度搜索点击器

    python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...

  3. Splinter学习--初探1,模拟百度搜索

    Splinter是以Selenium, PhantomJS 和 zope.testbrowser为基础构建的web自动化测试工具,基本原理同selenium 支持的浏览器包括:Chrome, Fire ...

  4. vue 使用watch监听实现类似百度搜索功能

    watch监听方法,watch可以监听多个变量,具体使用方法看代码: HTML: <!doctype html> <html lang="en"> < ...

  5. js/jQuery实现类似百度搜索功能

    一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  6. JS 实现百度搜索功能

    今天我们来用JS实现百度搜索功能,下面上代码: HTML部分: <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  7. 原生JS实现百度搜索功能

    今天呢给大家分享一下自己用原生JS做的一个百度搜索功能,下面上代码: <!DOCTYPE html> <html> <head> <meta charset= ...

  8. C#下利用正则表达式实现字符串搜索功能的方法(转)

    关键字:正则表达式.元字符.字符串.匹配: 1.正则表达式简介:正则表达式提供了功能强大.灵活而又高效的方法来处:.NET框架正则表达式并入了其他正则表达式实现的: 2.字符串搜索:正则表达式语言由两 ...

  9. JS---DOM---案例:模拟百度搜索框

    模拟百度搜索框 我的思路整理: 1. 注册文本框抬起事件(onkeyup) 2. 处理函数: --->创建临时数组,循环遍历文本框键入的文字内容和keywords数组,用keyWords[i]. ...

随机推荐

  1. Django复习

    django复习 django和其他框架的对比 django,集成很多功能的大型框架,为开发者提供了很多方便的组件:orm.form.ModelForm.auth.admin.contenttypes ...

  2. 安装Mysql5.6.19

    存在异常: ERROR (HY000): Can't connect to MySQL server on 'localhost' (10061) 原因:Mysql的服务没有启动 windows7启动 ...

  3. tensorflow:验证码的识别(中)

    三.训练识别模型 首先先拷贝一个nets文件夹,主要使用的是文件夹下的两个文件nets_factory.py.alexnet.py,用于导入训练使用的网络alexnet. nets_factory.p ...

  4. python pip install mysql-python报错

    报错: 下载地址: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

  5. Senparc.Weixin微信开发(2) 消息机制和上下文(Session)

    了解MessageHandler 为项目添加一个CustomMessageHandle.cs类 public class CustomMessageHandler : MessageHandler&l ...

  6. The authenticity of host 'slaver2 (192.168.199.132)' can't be established. RSA key fingerprint is cc:4e:23:01:ca:97:52:21:85:78:bc:29:ca:b3:12:52.

    1:ssh登录 The authenticity of host 192.168.199.132 can't be established. 的问题 问题出现了,总要解决吧,百度一下,详细介绍的很多, ...

  7. The connection string 'MysqlEF' in the application's configuration file does not contain the require异常

    在学习EF core first 对接mysql时,出现了这个异常. 原因是:连接字符串中缺少providerName="MySql.Data.MySqlClient" <a ...

  8. B - Alyona and towers CodeForces - 739C

    链接: https://vjudge.net/contest/202699#problem/B 题意: 给出一个序列,要支持区间加和操作 求其中最长的区间,该区间内的元素满足(ai<ai+1&l ...

  9. 【Android】Android 代码判断当前设备是否为模拟器

    [Android]Android 代码判断当前设备是否为模拟器 方法比较简单,直接粘贴代码 //判断当前设备是否是模拟器.如果返回TRUE,则当前是模拟器,不是返回FALSE public stati ...

  10. keepalived当主节点切换时脚本通知 lvs

    脚本 在keepalived.conf中添加 mail  查看邮件 实验dr实验模型 给director 做主从 4台服务器 rip:192.168.0.103 rip2:192.168.0.104 ...