1,获取链接上的参数

getQueryString = (name, search) => {
search = search || window.location.search.substr(1) || window.location.hash.split("?")[1];
let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
let r = search.match(reg);
if (r != null) return unescape(r[2]); return null;
}

  

  2、将数据导出为excel

function exportExcel(fileName, htmlStr) {
if (!htmlStr) htmlStr = document.getElementsByClassName('tableWrapper')[0].outerHTML
// 使用 outerHTML 属性获取整个 table 元素的 HTML 代码(包括<table>标签),
// 然后包装成一个完整的HTML文档,设置 charset 为 urf-8 以防止中文乱码
var html = "<html><head><meta charset='utf-8' /></head><body>" + htmlStr + '</body></html>'
// 实例化一个Blob对象,其构造函数的第一个参数是包含文件内容的数组,第二个参数是包含文件类型属性的对象
var blob = new Blob([html], {
type: 'application/vnd.ms-excel'
})
var a = document.createElement('a')
a.style.display = 'none'
// 利用URL.createObjectURL()方法为 a 元素生成 blob URL
a.href = URL.createObjectURL(blob)
// 设置文件名
a.download = `${fileName}.xls`
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}

  3、计算字符串宽度

function computeWidth(){
let textBox:any = document.createElement('span');
textBox.cssText = 'font-size: 18px;'
textBox.innerText = '文字文字文字'
document.body.appendChild(textBox);
let width = textBox.offsetWidth;
document.body.removeChild(textBox)
return width+50+'px'
}

  4.深拷贝

// 1、递归方式实现
function deepCopy(source,target) {
for(var key in source){
if(source.hasOwnProperty(key)){//只拷贝当前对象的属性
if(source[key] && typeof source[key] == "object"){//如果属性是引用类型的对象
// //根据原属性的类型决定是数组还是普通对象
target[key] = Array.isArray(source[key]) ? [] : {};
deepCopy(source[key],target[key]);//递归调用,完成所有层次的拷贝
}else{
target[key] = source[key];
}
}
}
}
deepCopy(p1,p2); // 2、借用JSON对象的parse和stringify
newobj = JSON.parse(JSON.stringify(obj))

  

  5.文本复制

        copyText(content) {
            if (!content) {
                console.log('文本不存在')
                return false
            }
            //创建一个input框存放需要复制的文本内容
            let copyUrl = document.createElement('input')
            copyUrl.setAttribute('value', content)
            document.body.appendChild(copyUrl)
            // 判断是在win还是ios
            if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                let range = document.createRange()
                range.selectNode(copyUrl)
                window.getSelection().addRange(range)
            } else {
                copyUrl.select()
            }
            const isSuccess = document.execCommand('Copy')
            copyUrl.remove()
            return isSuccess
        },

  

  6.判断鼠标坐标是否在元素里面

function mousePositionJudge(dom, e) {
let oElement = dom
let x1 = 0
let y1 = 0
for (x1 = 0, y1 = 0; oElement; oElement = oElement.offsetParent) {
x1 += oElement.offsetLeft
y1 += oElement.offsetTop
}
let x2 = x1 + dom.offsetWidth
let y2 = y1 + dom.offsetHeight
let x = e.pageX
let y = e.pageY
if (x > x1 && x < x2 && y > y1 && y < y2) {
return true
} else {
return false
}
}

最新文章

  1. Spring MVC入门知识总结
  2. java基础之 集合
  3. Java中LinkedList的remove方法真的耗时O(1)吗?
  4. 【转】Android Service完全解析,关于服务你所需知道的一切(下) ---- 不错
  5. Java中从控制台输入数据的几种常用方法(转)
  6. BuautifulSoup4库详解
  7. 【转】git-stash用法小结
  8. Java的两大数据类型
  9. docker之 网络模式和跨主机通信
  10. Maths | 离散K-L变换/ 主成分分析法
  11. highly variable gene | 高变异基因的选择 | feature selection | 特征选择
  12. 安装doxygen(一个自动文档生成工具)+Graphviz图形可视化软件
  13. oracle下导出某用户所有表的方法
  14. Volley的Get、Post方式(JsonObjectRequest、StringRequest)以及Volley获取图片的3种方式
  15. Ubuntu中敲写c语言步骤
  16. css overflow用法
  17. Vertica7 Native Connection Load Balance
  18. java-自定义标签&amp;&amp;JSTL标签库详解
  19. List_Delete
  20. react native 踩坑之 SectionList state更新 不执行render重新渲染页面

热门文章

  1. node.js &amp; fs &amp; file read &amp; file write
  2. ES Next &amp; Arrow function &amp; Promise &amp; Iterator &amp; Generator yield &amp; Async Await
  3. javascript &amp; global event &amp; custom event
  4. vue &amp; template &amp; v-else &amp; v-for bug
  5. SPC空投搅动市场,NGK算力持有者或成大赢家!
  6. Linux文件/proc/net/tcp分析
  7. Linux+Tomcat+Jdk1.8+jenkins环境搭建
  8. 看完了进程同步与互斥机制,我终于彻底理解了 PV 操作
  9. Django批量插入数据和分页器
  10. apiAutoTest:支持自定义函数,用例中可调用