随笔分类 -  JavaScript/jQuery

摘要:有一个需求是在已有列表中搜索关键词,然后在列表中展示含有相关关键字的数据项并且对关键字进行高亮显示,所以该需求需要解决的就两个问题: 1.搜索关键词过滤列表数据 2.每个列表高亮关键字 ps: 此问题基于数组对象,其他数据类型也可参考此思路。 关键词搜索:过滤数据很简单,无非就是监听search,对 阅读全文
posted @ 2019-09-26 11:56 小小lomo 阅读(14881) 评论(2) 推荐(1)
摘要:isElementInViewport (el, offset = 0) { const box = el.getBoundingClientRect(), top = (box.top >= 0), left = (box.left >= 0), bottom = (box.bottom <= ( 阅读全文
posted @ 2019-03-23 15:03 小小lomo 阅读(1776) 评论(0) 推荐(0)
摘要:var str = 'aa dd c dddd e';str = str.replace(/\s+/g, ' ');//将字符串里的多个连续空格替换成一个空格 阅读全文
posted @ 2018-09-09 11:16 小小lomo 阅读(1189) 评论(0) 推荐(0)
摘要://滚动条在内容更新时自动滚到底部var message = document.getElementById('message');message.scrollTop = message.scrollHeight; 阅读全文
posted @ 2018-08-22 17:13 小小lomo 阅读(2154) 评论(0) 推荐(0)
摘要:var m1 = moment('2018-08-14 11:00:00'), m2 = moment('2018-08-14 12:10:00'); console.log(m1)console.log(m2)console.log(m2.diff(m1, 'minute'));minute为分钟 阅读全文
posted @ 2018-08-14 18:08 小小lomo 阅读(17784) 评论(0) 推荐(0)
摘要:var str = 'sdfsdfds '; str.replace(/(^\s*)|(\s*$)/g, ""); 阅读全文
posted @ 2018-03-22 15:23 小小lomo 阅读(268) 评论(0) 推荐(0)
摘要:第一 JSON文件里面不能有任何注释,不能使用单引号,必须使用双引号; 第二 JSON文件名不能使用特殊字符 - ,比如 test-a.json 否则不会返回任何数据也不会报错。 使用方法: $.getJSON("your file path", function(data){ console.lo 阅读全文
posted @ 2018-02-27 14:32 小小lomo 阅读(1536) 评论(0) 推荐(0)
摘要:$(window).height(); //浏览器时下窗口可视区域高度 $(document).height(); //浏览器时下窗口文档的高度 ($(document.body).height();//浏览器时下窗口文档body的高度 $(document.body).outerHeight(true);//浏览器时下窗口文档body的总高度 包括border padding margin $... 阅读全文
posted @ 2018-01-22 10:07 小小lomo 阅读(340) 评论(0) 推荐(0)
摘要:html: js: 实现的思路就是响应键盘事件。下面是搜集到的keyCode: 阅读全文
posted @ 2018-01-16 09:43 小小lomo 阅读(8388) 评论(0) 推荐(0)
摘要:事件兼容 js停止冒泡· js阻止默认行为 阅读全文
posted @ 2018-01-08 15:26 小小lomo 阅读(105) 评论(0) 推荐(0)