随笔分类 - JavaScript
JavaScript
摘要:document.querySelector('a').onclick = (event) => { event = event || window.event event.preventDefault(); event.returnValue = false; }
阅读全文
摘要:IOS默认播放大屏播放,安卓播放可以同时播放多个,因为IOS默认是大屏播放所以不存在同时播放多个视频的现象。需求1、安卓一次播放一个视频,播放一个其中一个停止播放。 const videoList = document.getElementsByTagName("video"); const vid
阅读全文
摘要:function dispatchEventStroage () { const signSetItem = localStorage.setItem; localStorage.setItem = function (key, val) { let setEvent = new Event('se
阅读全文
摘要://防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); }
阅读全文
摘要:const beforeUpload = file => { var reader = new FileReader(); reader.readAsDataURL(file); //转化二进制流,异步方法 reader.onload = function(){ //完成后this.result为二
阅读全文
摘要:Blob 对象表示一个不可变、原始数据的类文件对象。它的数据可以按文本或二进制的格式进行读取,也可以转换成 ReadableStream 来用于数据操作。 前端展示原始文件有两种方式: 1、将接口直接写到 src 里面(比如 img 的src) > 不方便拿接口头字段信息。 2、转换为URL对象。
阅读全文
摘要://方式1:const copyText = (text, callback) => { // text: 要复制的内容, callback: 回调 var tag = document.createElement('input'); tag.setAttribute('id', 'copy_inp
阅读全文
摘要:!(function (doc, win) { // 拿到html标签的dom元素对象 var docEle = doc.documentElement, evt = "onorientationchange" in window ? "orientationchange" : "resize",
阅读全文
摘要:/** * 解决两个数相加精度丢失问题 * @param a * @param b * @returns {Number} */ function floatAdd(a, b) { var c, d, e; if(undefined==a||null==a||""==a||isNaN(a)){a=0
阅读全文
摘要:$(function(){ jQuery(document).ready(function () { if (window.history && window.history.pushState) { $(window).on('popstate', function () { /*当点击浏览器的
阅读全文
摘要:function getCookieByString(cookieName){ var start = document.cookie.indexOf(cookieName+'='); if (start == -1) return false; start = start+cookieName.l
阅读全文
摘要://获取本地ip function getIPAdress() { var interfaces = require('os').networkInterfaces(); for (var devName in interfaces) { var iface = interfaces[devName
阅读全文
摘要:https://blog.csdn.net/ixygj197875/article/details/79090578
阅读全文
摘要:解决方法: 1、回调 (利用函数回调将返回值带出去。) 2、 利用promise 3、async解决方式。 常用的就是这三种,还可以利用 generator 解决问题。 next() ....
阅读全文
摘要:function getBase64 (file) { return new Promise(function (resolve, reject) { let reader = new FileReader() let imgResult = '' reader.readAsDataURL(file
阅读全文
摘要:import Vue from 'vue' import axios from 'axios' Vue.prototype.$download = function download(url,param) { axios.get(url, { responseType: 'blob', params
阅读全文
摘要:var star='2019-2-26'//date1:小日期 对比时间日期 var end='2019-3-5'//date2:大日期 当前日期 function DateMinus(date1,date2){ var sdate = new Date(date1); var now = new
阅读全文
摘要:<script type="text/javascript">function checknum(){ var obj = document.getElementById("num"); var reg = new RegExp("^[0-9]*$"); if(!reg.test(obj.value
阅读全文
摘要:function randomColor1(){ var r=Math.floor(Math.random()*256); var g=Math.floor(Math.random()*256); var b=Math.floor(Math.random()*256); //在控制器中显示出随机生成
阅读全文