首页
Search
1
解决visual studio code (vscode)安装时没有选择安装路径问题
328 阅读
2
如何在 Clash for Windows 上配置服务
227 阅读
3
Arch Linux 下解决 KDE Plasma Discover 的 Unable to load applications 错误
151 阅读
4
Linux 下 Bash 脚本 bad interpreter 报错的解决方法
151 阅读
5
uniapp打包app提示通讯录权限问题,如何取消通讯录权限
117 阅读
clash
服务器
javascript
全部
游戏资讯
登录
Search
加速器之家
累计撰写
1,517
篇文章
累计收到
0
条评论
首页
栏目
clash
服务器
javascript
全部
游戏资讯
页面
搜索到
1517
篇与
的结果
2024-08-22
JS实现多个数据相加
有时我们进行多个数据相加,组合成一个数组,我们可以使用下面方法来实现let arr1 = [1,2,3,4,5,6]; let arr2 = [11,12,13,14,15,16]; let arr3 = [10,21,31,41,51,61]; let json = {arr1,arr2,arr3}; //json中有任意多个数组 //let json = [arr1,arr2,arr3]; //也可以使用数组形式,自行替换测试看结果 //保存结果的数组 let result = []; //遍历json for(let key in json){ //遍历数组的每一项 json[key].forEach((value,index) => { if( isBlank(result[index]) ){ result[index] = 0 ; } result[index] += value ; }) } //打印结果 console.log(result); //[22, 35, 47, 59, 71, 83] //判断值是否存在函数 function isBlank(val){ if(val == null || val == ""){ return true; } }
2024年08月22日
9 阅读
0 评论
0 点赞
2024-08-22
js如何防止ajax重复提交表单
很多开发者在做表单提交数据到后台的时候,会出现多提交一次,多一条数据的情况,这种原因的是因为服务端未能及时响应结果(网络延迟,并发排队等因素),导致前端页面没有及时刷新,用户有机会多次提交表单如果提交对象为按钮的话,可以对按钮设置disabled,此办法适应于按钮提交,此种方法简单粗暴,也是很多人用的办法:$(".sub").attr('disabled',true)//在按钮提交之后和AJAX提交之前将按钮设置为禁用 $.ajax({ url:'/post.php' data:{a:1,b,1} success:function(){ $(".sub").attr('disabled',false)//在提交成功之后重新启用该按钮 }, error: function(){ $(".sub").attr('disabled',false)//即使AJAX失败也需要将按钮设置为可用状态,因为有可能是网络问题导致的失败,所以需要将按钮设置为可用 } })
2024年08月22日
12 阅读
0 评论
0 点赞
2024-08-22
如何使用JavaScript获取扫码枪扫码数据,执行相应的操作
扫码枪在日常生活中,经常可以看到,比较多的就是超市,网页中我们需要用获取扫码枪的值,就需要用到JavaScript来获取,后再执行操作。JavaScript获取扫码枪数据,扫码枪相当于键盘输入设备,输入一连串数字后加一个enter键。以下教大家怎么获取扫码枪的值:1、放置文本框:首先放置文本输入框,用于接收扫码枪赋值(如果不想显示输入框,可以使用样式将其隐藏即可)<input type="text" class="codevalue" >2、聚焦文本框:设置定时聚焦文本框,每隔半秒执行一次聚焦,防止文本框失去焦点setInterval(function() { $('.codevalue').focus() console.log('连接成功') }, 500); //1000毫秒等于1秒钟3、文本框赋值:获取扫码枪的值,并赋值给文本框var char = ""; //记录扫描枪输入的内容 var lastTime=null;//上次输入的时间 var nextTime=null;//这次输入的时间 var lastCode=null;//上次输入的键值(接收到的为ASCII值) var nextCode=null;//这次输入的键值(接收到的为ASCII值) $(document).keydown(function(event){ nextTime = new Date().getTime();//获取当前键入的时间 //判断是否输入了回车按钮,并确认是扫描枪键入的值 if (event.keyCode === 13 && char !== "" && nextTime - lastTime <= 30){ //把监听到的数据显示在我的文本框上 $(".codevalue").val(char); console.log('获取到值1--' +char) //清空数值,以便下一次扫描 char = ""; lastCode = null; lastTime = null; }else { //获取键入的键值 nextCode = event.keyCode; //如果是第一个字母你可以进行一些代码增强,我这里并没有处理,直接转换了 if(lastCode == null && lastTime == null){ //初始字母 char = String.fromCharCode(nextCode); //写入你要增强的代码。。。 // console.log('获取到值2--' +char) //判断是否是扫描枪键入的值 }else if(lastCode != null&&lastTime!= null && nextTime - lastTime <= 30){ //键入的值为ASCII码,要获取对应得值,需要转换一下 char += String.fromCharCode(nextCode);//存到char中,拼接上次的结果 } else{ //判断为手动输入,不做任何处理,数据保持为null即可 // alert("suck"); char = ""; lastTime=null; nextTime=null; lastCode=null; nextCode=null; } //lastCode、lastTime为中间变量,存储数据,让nextCode与nextTime可以存新数据 //nextCode与nextTime要存储新键入按钮的信息 lastCode = nextCode; lastTime = nextTime; } })4、执行操作:监听文本的值,执行后置操作$('.codevalue').change(function () { //获取选中下拉框的属性值 let val = $('.codevalue').val(); $('.codevalue').focus() //这里写逻辑代码 })这就是简单的获取扫码枪值的方法,供大家参考。
2024年08月22日
16 阅读
0 评论
0 点赞
2024-08-22
JavaScript点击按钮或F11键盘实现全屏以及判断是否是全屏
有时候我们做一些网页活动,需要用到全屏,我们可以使用JavaScript点击按钮或F11键盘实现全屏以及判断是否是全屏1、点击按钮实现全屏<script> // 全屏显示 $(".translate").click(function(){ document.documentElement.requestFullscreen() $('.contron').hide(); }) </script>2、判断是否是全屏,用于执行后续操作<script> /** * @description: 检测有没有元素处于全屏状态 * @return false: 当前没有元素在全屏状态 * @return true: 有元素在全屏状态 */ function isEleFullScreen() { const fullScreenEle = document.fullscreenElement || document.msFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement; if (fullScreenEle === null) { return false; } else { return true; } }; </script>3、监听全屏事件,判断元素是否隐藏<script> //监听退出全屏事件 window.onresize = function() { // console.log(isEleFullScreen()) if(isEleFullScreen()==true){ $('.contron').hide(); }else{ $('.contron').show(); } } </script>4、监听用户按下键盘F11键,阻止默认行为,执行全屏// 监听f11键 $(document).keydown(function(event) { if (event.which == 122) { // 122是F1键的键码 event.preventDefault(); // 阻止默认行为 // 在此处添加您的代码以响应F11键事件 document.documentElement.requestFullscreen() //全屏 $('.contron').hide(); } });这里默认打开网页是有全屏按钮的,点击全屏按钮,会自动隐藏全屏按钮,按下键盘全屏快捷按钮,实现全屏,点击ESC按钮或者F11退出全屏,显示全屏按钮。
2024年08月22日
11 阅读
0 评论
0 点赞
2024-08-12
WordPress 使用 WP-CLI 批量更换域名
本文将指导如何在 Debian 11 和 Ubuntu 20.04 下 WP-CLI 更换 WordPress 域名。PS:本文同时适用于任意 Linux 系统,请自行承担使用风险前提背景有时候我们需要给 WordPress 更换域名,大多数网上的教程是要你从 phpMyAdmin 提交 SQL 语句,而且大多数教程要你修改的表就两个,实际上有三个。对于本站的读者来说,我们都有 root 权限了,不需要这货,此时我们直接拿出大杀器,WordPress 官方的 WP-CLI 工具。安装 WP-CLI按照官方教程,直接安装:wget -O wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp 此时即可通过 wp --info 命令查看 WP-CLI 信息:root@wordpress ~ # wp --info OS: Linux 5.10.0-11-cloud-amd64 #1 SMP Debian 5.10.92-2 (2022-02-28) x86_64 Shell: /usr/sbin/nologin PHP binary: /usr/bin/php8.1 PHP version: 8.1.3 php.ini used: /etc/php/8.1/cli/php.ini MySQL binary: /usr/bin/mysql MySQL version: mysql Ver 15.1 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64) using readline EditLine wrapper SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /root WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.6.0 批量替换 WordPress 域名首先,按照本站的 LEMP 或 LAMP 教程,复制一份 Nginx 或 Apache 的配置,让其同时生效新旧域名,记得 SSL 证书也需要更新。然后,进入 WordPress 的安装目录,假设目录为 /var/www/example.com 旧的 URL 为 https://old.example.com,需要替换的新的 URL 为 https://new.example.com:cd /var/www/example.com sudo -u www-data wp search-replace 'https://old.example.com' 'https://new.example.com' --dry-run 此时并不会真正施行替换命令,因为我们加了 --dry-run 参数,你可以看到需要替换的条目数是否和预估的匹配:root@wordpress /var/www/example.com # sudo -u www-data wp search-replace 'https://old.example.com' 'https://new.example.com' --dry-run +------------------+-----------------------+--------------+------+ | Table | Column | Replacements | Type | +------------------+-----------------------+--------------+------+ | wp_commentmeta | meta_key | 0 | SQL | | wp_commentmeta | meta_value | 0 | SQL | | wp_comments | comment_author | 0 | SQL | | wp_comments | comment_author_email | 0 | SQL | | wp_comments | comment_author_url | 0 | SQL | | wp_comments | comment_author_IP | 0 | SQL | | wp_comments | comment_content | 15 | SQL | | wp_comments | comment_approved | 0 | SQL | | wp_comments | comment_agent | 0 | SQL | | wp_comments | comment_type | 0 | SQL | | wp_links | link_url | 0 | SQL | | wp_links | link_name | 0 | SQL | | wp_links | link_image | 0 | SQL | | wp_links | link_target | 0 | SQL | | wp_links | link_description | 0 | SQL | | wp_links | link_visible | 0 | SQL | | wp_links | link_rel | 0 | SQL | | wp_links | link_notes | 0 | SQL | | wp_links | link_rss | 0 | SQL | | wp_options | option_name | 0 | SQL | | wp_options | option_value | 2 | PHP | | wp_options | autoload | 0 | SQL | | wp_postmeta | meta_key | 0 | SQL | | wp_postmeta | meta_value | 1 | PHP | | wp_posts | post_content | 331 | SQL | | wp_posts | post_title | 0 | SQL | | wp_posts | post_excerpt | 0 | SQL | | wp_posts | post_status | 0 | SQL | | wp_posts | comment_status | 0 | SQL | | wp_posts | ping_status | 0 | SQL | | wp_posts | post_password | 0 | SQL | | wp_posts | post_name | 0 | SQL | | wp_posts | to_ping | 0 | SQL | | wp_posts | pinged | 0 | SQL | | wp_posts | post_content_filtered | 0 | SQL | | wp_posts | guid | 19315 | SQL | | wp_posts | post_type | 0 | SQL | | wp_posts | post_mime_type | 0 | SQL | | wp_term_taxonomy | taxonomy | 0 | SQL | | wp_term_taxonomy | description | 0 | SQL | | wp_termmeta | meta_key | 0 | SQL | | wp_termmeta | meta_value | 0 | SQL | | wp_terms | name | 0 | SQL | | wp_terms | slug | 0 | SQL | | wp_usermeta | meta_key | 0 | SQL | | wp_usermeta | meta_value | 0 | PHP | | wp_users | user_login | 0 | SQL | | wp_users | user_nicename | 0 | SQL | | wp_users | user_email | 0 | SQL | | wp_users | user_url | 0 | SQL | | wp_users | user_activation_key | 0 | SQL | | wp_users | display_name | 0 | SQL | +------------------+-----------------------+--------------+------+ Success: 19664 replacements to be made. 我们可以看到,基本上就 comment_content,post_content 和 guid 需要替换,没有问题的话就直接执行:cd /var/www/example.com sudo -u www-data wp search-replace 'https://old.example.com' 'https://new.example.com' 执行完成后会出现类似 Success: Made 19664 replacements. 的提示。注意,如果之前没有开启过 HTTPS,那么你可能需要使用 http://old.example.com 来替换,建议执行两次,不推荐直接执行替换 old.example.com。修改 wp-config.php我们也可以打开 wp-config.php,加入下面两行代码来完成新的域名替换:define('WP_HOME','https://new.example.com/'); define('WP_SITEURL','https://new.example.com/'); 修改 WordPress 后台设置我们也可以进入 WordPress 后台,在常规设置里更换新的域名,进入 https://new.example.com/wp-admin/options-general.php 然后更换 WordPress 地址(URL) 和 站点地址(URL)这两种方法治标不治本,仅对新的文章参数生效,旧的文章和评论地址里都是旧域名,所以我们还是推荐使用 WP-CLI 直接替换新的域名。最后别忘了更新 Nginx 或 Apache 配置,让旧的域名跳转到新的域名:Nginx 配置如下server_name old.example.com; return 301 https://new.example.com$request_uri; Apache 配置如下RewriteEngine On RewriteCond %{HTTP_HOST} ^old.example.com[NC] RewriteRule ^(.*)$ https://new.example.com$1[R=301,L]
2024年08月12日
23 阅读
0 评论
0 点赞
1
...
293
294
295
...
304