2022-09-14 js使用window.onload覆盖问题的解决方法 js使用window.onload覆盖问题的解决方法 解决多人开发时,同时使用window.onload事件所出现的后面的window.onload函数覆盖前面一个window.onload函数的问题。<script> // 第一种,使用addEventListener window.onload = function () { console.log("第一次调用"); } function twofunction() { console.log("第二次调用"); } window.addEventListener("load",twofunction); // 第二种,封装window.onload,使用addLoadEvent,但直接使用window.onload还是会被替换的 function addLoadEvent(func) { var oldonload = window.onload; if (typeof wi... 2022年09月14日 883 阅读 0 评论
2022-09-03 原生js封装ajax 原生js封装ajax function ajax(options) { var xhr = null; var type = 'GET'; var params = formsParams(options.data); if (typeof options.type != 'undefined') { type = options.type.toUpperCase(); } //创建对象 if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } if (typeof options.async == "undefined") { options.async = true; } // 设置超时时间(毫秒) if (typeof options.timeout == "undefined&qu... 2022年09月03日 823 阅读 0 评论
2022-06-06 js执行提示Uncaught URIError: URI malformed js执行提示Uncaught URIError: URI malformed 由于decodeURI转码时,通过%进行解析,如果字符串中存在%则会出现URI malformed解决方法将字符串中的%替换为25%就行了var str = '1%2'; if(str.indexOf('%') > -1) { str = str.replace(/%/g,'%25'); } 2022年06月06日 1,056 阅读 0 评论
2022-05-21 JQuery长按事件 JQuery长按事件 $(".text").on({ touchstart: function(e) { var oSpan = e.currentTarget.lastElementChild // 长按事件触发 timeOutEvent = setTimeout(function() { timeOutEvent = 0; console.log('你长按了'); }, 500); }, touchmove: function() { clearTimeout(timeOutEvent); timeOutEvent = 0; }, touchend: function() { clearTimeout(timeOutEvent); if (timeOutEvent != 0) { console.log('你点击了'); ... 2022年05月21日 883 阅读 0 评论
2022-04-04 js实现html导出为PDF文件 js实现html导出为PDF文件 html2canvas官网:http://html2canvas.hertzen.com/<?php if(!empty($_POST['datauri'])){ if(preg_match('/data:.*?;base64,/i',$_POST['datauri'])){ $datauri = base64_decode(preg_replace('/data:.*?;base64,/i','',$_POST['datauri'])); $dir = 'upload/'; if(!is_dir($dir)){ mkdir($dir); } $file = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR']).'.pdf'; try { file_put_contents($dir.$file,$datauri); $data = ['... 2022年04月04日 1,328 阅读 0 评论
2022-01-18 JS实现随机抽奖功能 JS实现随机抽奖功能 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .container { width: 600px; height: 600px; border: 1px solid; display: flex; flex-wrap: wrap; margin: 100px auto; } .block { ... 2022年01月18日 1,103 阅读 0 评论
2021-12-25 关于¬ify_url变成¬ify_url的解决方法 关于¬ify_url变成¬ify_url的解决方法 在页面上显示¬ify_url不管怎样都变成¬ify_url,后来发现把&改为&就可以了PHP字符替换$str = '¬ify_url'; $url = str_replace("&","&",$str); js字符替换str = '¬ify_url'; url = str.replace(/&/, "&"); 2021年12月25日 1,368 阅读 0 评论
2021-12-02 js判断数组中是否存在某个元素 js判断数组中是否存在某个元素 方法一:array.indexOf(item,start)实际用法:if(arr.indexOf(某元素) > -1){//则包含该元素}var fruits = ["Banana", "Orange", "Apple", "Mango"]; var a = fruits.indexOf("Apple"); // 2 方法二:array.find()arr = [1,2,3,4,5]; arr.find(function(value) { if(value === 要查找的值) { //包含该元素 } }) 方法三:jQuery.inArray()arr = [1,2,3,4,5]; index = $.inArray(2,arr); if(index > -1){ console.log('包含该元素') } 2021年12月02日 874 阅读 0 评论
2021-11-25 js获取时间戳,时间戳格式化日期 js获取时间戳,时间戳格式化日期 js获取当前时间戳的方法var timestamp = Date.parse(new Date())/1000;//获取当前秒的时间戳 var timestamp = (new Date()).valueOf();//获取当前毫秒的时间戳 var timestamp = new Date() . get Time();//返回数值单位是毫秒 js获取指定时间戳的方法var timestamp = (new Date(" 2021/11/25 20:00:20")).getTime()/1000; 格式化日期function dateFormat(thisDate, fmt) { var o = { "M+": thisDate.getMonth() + 1, "d+": thisDate.getDate(), "h+": thisDate.getHours(), "m+": thisDate.getMinut... 2021年11月25日 992 阅读 0 评论
2021-09-20 页面加载时增加loading效果 页面加载时增加loading效果 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> #loading { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2000; opacity: 1; background: #f7f7f7; ... 2021年09月20日 860 阅读 0 评论