WishMeLz

生活其实很有趣

分类 JS 下的文章

1900年至2100年公历、农历互转Js代码

/**公历年月日转农历数据 返回json**/ calendar.solar2lunar(2000,8,23); /**农历年月日转公历年月日**/ calendar.lunar2solar(2000,7,24);Animal: "龙" IDayCn: "廿四" IMonthCn: "七月" Term: "处暑" astro: "处女座" cDay: 23 cMonth: 8 cYear: 2000 gzDay: "癸丑" gzMonth: "甲申" gzYear: "庚辰" isLeap: false isTerm: true isToday: ...

NodeJs抓取页面

npm i cheerio request iconv-lite思路:通过 request 获取到页面。在使用 iconv-lite 编译数据。在使用 cheerio 拿到对应的元素。这里以抓取微博热搜为例const cheerio = require('cheerio'); const request = require('request'); const iconv = require('iconv-lite'); function http(url, decode = 'utf8') { return new Promise((res...

随机数

function getRandom(start, end, fixed = 0) { let differ = end - start let random = Math.random() return (start + differ * random).toFixed(fixed) }getRandom(1,5) 1<= num >=5

保存图片文件,下载图片

function downloadIamge(imgsrc, name) { //下载图片地址和图片名 let image = new Image(); // 解决跨域 Canvas 污染问题 image.setAttribute("crossOrigin", "anonymous"); image.onload = function () { let canvas = document.createElement("canvas"); ...

赛邮云通信SUBMAIL

NodeJs发送短信var request = require('request'); let post = function (url, postdata) { let options = { url: url, formData: postdata }; return new Promise(function (resolve, reject) { request.post(options, function (err, response, body) { ...

粘贴图片 ctrl+v

document.addEventListener("paste", function (event) { var isChrome = false; if (event.clipboardData || event.originalEvent) { //某些chrome版本使用的是event.originalEvent var clipboardData = event.clipboardData || event.originalEvent.clipboard...

JS判断是否为IE浏览器

function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 var isEdge = userAgent.indexOf("Edge") > -1 ...

复制到剪切板

copy(val) { let oInput = document.createElement("input"); oInput.value = val; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); this.$message({ message: "复制成功", type: "success", ...

正则

https://regex-vis.osrc.com/ https://hate-regex.osrc.com/数字data = data.replace(/[^\.\d]/g, "") // 数字 data = data.replace(".", "") // 去掉小数点小数两位data = data.replace(/[^\.\d]/g,"") // 数字 data = data.replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3") // 小数点后视频图片var...

JS-Cookie

function getCookie(cookie_name) { var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(cookie_name); if (cookie_pos !== -1) { cookie_pos = cookie_pos + cookie_name.length + 1; var cookie_end = allcookies.ind...

JS常用方法

加号运算符// 可以做到转换格式 let a = '12' let b = + a + 12; let c = a - 0 + 12 let d = a + 12; console.log(b); // 24 console.log(c); // 24 console.log(d); // 1212动态绑定属性// 在with中可以操作对象的每一项 let tom = { name: "tom", height: 170, sex: "男" } with(tom){ height++ console.lo...

JS判断是否在当前页面

var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null; var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange'); ...

JS获取URL参数

function GetQueryValue(key) { // 获取?后面的参数 var query = decodeURI(window.location.search.substring(1)); // 通过 & 切割为数组 ["naem=tom"] var queryArr = query.split("&"); // 循环遍历 在将每一项通过 = 切割 做判断key for (var i = 0; i < queryArr.length; i+...

JS笔记

直接返回时间戳:Date.now();当前时间 let newDate = new Date(); let strData = `${newDate.getFullYear()}-${newDate.getMonth() + 1}-${newDate.getDate()} ${newDate.getHours()}:${newDate.getMinutes()}:${newDate.getSeconds()}` console.log(strData);VIDEO倍速:playbackRate

各浏览器的用户代理字符串整理

1. IE 和 IE Mobile 浏览器WindowsIE 9Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)WindowsIE 10Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)WindowsIE 11Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like GeckoWindows PhoneIE 10M...