script跨域之360搜索
思考:
布局:
1,flex元素上下左右居中,内部元素横向排列;
div{
/* 100vh = viewport height*/
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
2,input输入框与input type=“button”按钮对齐,给属性值vertical-align:top;
3,input输入框去除默认样式 {border:none;outline:none;}
js原理解析,理解注释
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模拟360搜索</title>
<style>
body{padding:0;margin:0;overflow:hidden;}
ul,li{margin:0;padding:0;}
ul{border:1px solid #ccc;border-top:0;width:522px;margin-left:-110px;}
li{list-style:none;padding:5px;text-align:left;text-indent:10px;cursor:pointer;}
.main{
/* 100vh = viewport height*/
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.skin-search-input{
width:500px;
background: #fff;
height: 34px;
padding: 4px 10px 4px 12px;
vertical-align: top;
border: 1px solid #ccc;
}
.keyword{
background: #fff;
border: none;
color: #333;
font-size: 16px;
height: 30px;
line-height: 30px\9;
margin-top: 3px;
outline: none;
width:100%;
}
input[type=button]{
-webkit-appearance: none;
border: 0;
cursor: pointer;
font-size: 18px;
height: 44px;
outline: none;
vertical-align: top;
width: 110px;
background: #19b955;
color: #fff;
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
</head>
<body> <div class="main">
<div class="skin-search-input">
<input type="text" class="keyword">
</div>
<input type="button" value="搜一下">
</div>
<div align="center" class="message" style="display:none;">
<ul>
</ul>
</div> <script>
//如果页面加载直接给li元素绑定事件,你是获取不到li元素的。
//解决方案,可以用jq给我们提供的事件委托
$(".message>ul").on("mouseover","li",function () {
this.style.background = "#efefef";
});
$(".message>ul").on("mouseout","li",function () {
this.style.background = "white";
}); function getInfo(data) {//回调函数
//解析数据,然后把message里面的ul里面的li元素的数据替换
var results = data.result;
var i;
document.querySelector(".message>ul").innerHTML = "";
for(i=0;i<results.length;i++){
var li = document.createElement("li");
li.innerHTML = results[i].word;
console.log(li);
document.querySelector(".message>ul").appendChild(li);
}
} //添加键盘事件
document.querySelector(".keyword").onkeyup = function () {
var keyword = this.value; //如果在输入的时候有空格的话,这里需要做判断
if(keyword.length>0){
//我根据这个关键字去获取数据,获取到数据之后
//加载到列表里
//显示
document.querySelector(".message").style.display = "block";
//把关键字给360的这个搜索接口,让它来给我结果 //使用script标签去发送请求
var tag = document.createElement("script");
tag.src = "https://sug.so.360.cn/suggest?callback=getInfo&encodein=utf-8&encodeout=utf-8&format=json&fields=word,obdata&word="+keyword;
document.body.appendChild(tag);
}else{
document.querySelector(".message").style.display = "none";
}
}
</script>
</body>
</html>
script跨域之360搜索的更多相关文章
- jsonp跨域请求360数据乱码解决办法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- vue中的跨域问题
https://segmentfault.com/a/1190000011072725(原文) 使用vue-axios和vue-resource解决vue中调用网易云接口跨域的问题 注(api很重 ...
- ajax 跨域的问题 用js绕过跨域
之前遇到一个ajax跨域的问题,搜索了很多方法才找到解决方案,也怪自己 菜鸟一个 这些经验还是要慢慢来的 尤其是最近来回顾一下 竟然发现自己忘记了 所以还是把它记下来啊 免得到时候忘记 这个方法原 ...
- JS跨域
//2011-7-25 (function(){ //闭包 function load_script(xyUrl, callback){ var head = document.getElements ...
- ajax跨域jsonp
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...
- jQuery的jsonp跨域是这么回事.
实现跨域请求的有iframe,img,script中的src属性.那么jquery是如何解决跨域请求的呢? 一:项目jsonp2中有个app.js文件,代码如下: function app(json) ...
- jsonp跨域请求学习笔记
前言 ajax,用苍白的话赞扬:很好. 我们可以使用ajax实现异步获取数据,减少服务器运算时间,大大地改善用户体验:我们可以使用ajax实现小系统组合大系统:我们还可以使用ajax实现前端的优化.( ...
- ajax跨域请求学习笔记
原文:ajax跨域请求学习笔记 前言 ajax,用苍白的话赞扬:很好. 我们可以使用ajax实现异步获取数据,减少服务器运算时间,大大地改善用户体验:我们可以使用ajax实现小系统组合大系统:我们还可 ...
- sonp跨域请求
sonp跨域请求学习笔记 前言 ajax,用苍白的话赞扬:很好. 我们可以使用ajax实现异步获取数据,减少服务器运算时间,大大地改善用户体验:我们可以使用ajax实现小系统组合大系统:我们还可以 ...
随机推荐
- 阿里云 oss python3 样例
阿里云的oss SDK又是不支持python3,头疼头疼. 本想改一改它的SDK,让它支持python2+python3,无奈里面大量的代码使用不带括号的print.工作量恐怖. 幸好oss的使用很e ...
- MVC项目发布到IIS遇到的问题
MVC4 + .NET Framework 4.5 +Windows Server 2008+ IIS7.5 + 4.0集成模式池 ,发布后可能会遇到404.0 或者403.14错误,在web.con ...
- javascript解析器(引擎)
The JavaScript interpreter in a browser is implemented as a single thread. javascript 引擎在浏览器中作为单线程实现 ...
- (转)解决WinDbg调试Dump文件不同环境mscordacwks.dll版本问题
解决WinDbg调试Dump文件不同环境mscordacwks.dll版本问题 开发人员提交一个dump文件(Windows Server 2008 R2),当前调试环境Windows Serve ...
- Ubuntu13.04使用Jlink和ST-Link V2烧写STM32F1x和STM32F4x
近期做研究openpilot和crazyflie2.0,都须要在Linux进行代码的编写和烧录,所以研究了下Linux下如何使用Jlink,还有开源的支持多个仿真器的openocd,可是困难重重.总是 ...
- Mysql暴错注入代码-webshell
MySql Error Based Injection Reference[Mysql暴错注入参考]Author:Pnig0s1992Mysql5.0.91下测试通过,对于5+的绝大部分版本可以测 ...
- mysql启动与关闭
撰于:http://wenku.baidu.com/link?url=QV3mEJWnU4c8VZPjKGxz4A8gSmdjO2HZY7n963UaVx4l_uPKrh16tGxLyqjf5i3MA ...
- Vivado 自带IP仿真问题
可以新建一个测试工程,通过IP catalog直接生产IP核,在IP核上右键选择 Open IP Example Design 之后选择生成路径. 启动Run Simulation.
- List 通过 Collections.binarySearch 进行记录筛选
1. Collections.sort(list, new Comparator<TreeDto>() { @Override public int compare(TreeDto a2, ...
- Redis-ha(sentinel)搭建
服务器描述:本次搭建是用来测试,所以是在一台服务器上搭建三个redis服务(一主两从) 服务角色 端口 Redis.conf名称 sentinel配置文件名称 sentinel端口 redis日志路径 ...