
JS基础知识点
js基础相关知识点
PENG121.
这个作者很懒,什么都没留下…
展开
-
JS,对数字实现三位分割显示不足三位自动补全三位
toOrderNum(num) { let stnum = num; let splitNum = Number(stnum).toLocaleString(); if (splitNum.length < 13) { if (splitNum.length % 4 == 1) { splitNum = `00${splitNum}` } else if (splitNum.length % 4 == 2) {原创 2021-03-10 16:02:12 · 643 阅读 · 0 评论 -
JS括号匹配算法
let testFun = (str) => { let container = []; let match = { "}": "{", "]": "[", ")": "(" }; for (x of str.split("")) { if ((x == "{" || x == "[" || x == "(") && container.indexOf(x) < 0) { container.push(x); } else { if (container原创 2020-09-10 14:49:02 · 346 阅读 · 0 评论 -
生成【5-10】随机数(整数)
10 - parseInt(Math.random() * 6)原创 2020-09-08 17:49:55 · 2690 阅读 · 0 评论 -
千分位算法实现
function format(v) { const reg = /\d{1,3}(?=(\d{3})+$)/g return `${v}`.replace(reg, '$&,')}g代表全局通用原创 2020-09-05 21:31:43 · 425 阅读 · 1 评论 -
处理部分浏览器底部出现左右箭头栏
function pushHistory() { var state = { title: "title", url: "#" }; window.history.pushState(state, "title", "#"); } pushHistory(); setTimeout(function () {...原创 2020-08-27 09:43:49 · 762 阅读 · 0 评论 -
创建dom,并且点击弹出对应的序列
const list = document.getElementById('list')// 创建一个文档片段,此时还没有插入到DOM接口中const frag = document.createDocumentFragment()for (let i = 0; i < 10; i++) { const li = document.createElement('li') li.innerHTML = `LIST ITEM ${i}` li.addEventListener('click',原创 2020-08-15 10:04:14 · 140 阅读 · 0 评论 -
手写Ajax
function ajax (url) { const p = new Promise((resolve, reject) => { const xhr = new XMLHttpRequest() xhr.open('get', url, true) xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { resolve(JSON.p原创 2020-08-14 08:53:43 · 209 阅读 · 0 评论 -
闭包
所有的自由变量的查找,是在函数定义的地方,向上级作用域查找不是在执行的地方!!!/** * 函数作为返回值 */function create() { const a = 100 return function () { console.log(a) }}const fn = create()const a = 200fn() // 100/** * 函数作为参数被传递 */function print(fn) { const a = 200 fn()}cons原创 2020-08-11 22:51:25 · 181 阅读 · 1 评论 -
点击复制标签内容
<script> $('.content-news .zm-code .copy-btn').on('click', function () { copyUrl() }) function copyUrl() { var $tempCopy = $("<input>"); $("body").append($tempCopy); $tempC原创 2020-08-11 11:28:17 · 248 阅读 · 0 评论 -
获取当前时间--年月日时分秒
function getNowFormatDate () { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); var month = date.getMonth() + 1; var hour = date.getHours(); var minutes = date.getMinutes();...原创 2020-07-27 09:42:12 · 347 阅读 · 0 评论