Welcom to 评论 - lizhenqiu blog!
#913
#914
#915
<p style="line-height: 18px; font-size: 18px; font-family: times;"> Click "<i>Load samples</i>" to view and edit more JS samples.<br> <br> Labyrinth generated with JavaScript:<br><br> <script> for (var line=1; line<60; line++) { for(var i=1;i<29;i++) { var s = (Math.floor((Math.random()*2)%2)) ? "╱" : "╲"; document.write(s); } document.writeln("<br>"); } </script> </p>
<!doctype html> <html> <body> <canvas id="can" width="400" height="400" style="background: Black"></canvas> <script> var sn = [ 42, 41 ], dz = 43, fx = 1, n, ctx = document.getElementById("can").getContext("2d"); function draw(t, c) { ctx.fillStyle = c; ctx.fillRect(t % 20 * 20 + 1, ~~(t / 20) * 20 + 1, 18, 18); } document.onkeydown = function(e) { fx = sn[1] - sn[0] == (n = [ -1, -20, 1, 20 ][(e || event).keyCode - 37] || fx) ? fx : n }; !function() { sn.unshift(n = sn[0] + fx); if (sn.indexOf(n, 1) > 0 || n<0||n>399 || fx == 1 && n % 20 == 0 || fx == -1 && n % 20 == 19) return alert("GAME OVER"); draw(n, "Lime"); if (n == dz) { while (sn.indexOf(dz = ~~(Math.random() * 400)) >= 0); draw(dz, "Yellow"); } else draw(sn.pop(), "Black"); setTimeout(arguments.callee, 130); }(); </script> </body> </html>
#916
let a = 1, b = 2; [a, b] = [b, a];
(10)["toString"]() === "10" 写成 10..toString() === "10" 更显装逼~
console.log( '1.0123'.replace(/\B(?=(\d{3})+(?!\d))/g, ',')) result: 1.0,123
Math.random().toString(36).substring(2)
Math.random()
const find = (arr,x) => arr.filter(num=>num===x)[0]||null;
[...'8'.repeat(6)]
if(~"asdf".lastIndexOf("a")){ alert("exists"); }
#917
window.onerror = function(m, f, l){ return true }
#918
eg:!!0 === false
#919
(23333333).toLocaleString('en-US')
#920
#921
#922
#923
#924
#925
$("#id").on(' touchstart',function(){ $("#id").on('touchmove',function(event) { event.preventDefault(); }, false);})$("#id").on(' touchend',function(){ $("#id").unbind('touchmove');})
$("body").bind("touchmove",function(event){event.preventDefault;//code});
$("body").unbind("touchmove");
#926
function is_email($str){ //检验email return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str); } function is_url($str){ //检验网址 return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"]) *$/", $str); } function is_qq($str){ //检验qq return preg_match("/^[1-9]\d{4,8}$/", $str); } function is_zip($str){ //检验邮编 return preg_match("/^[1-9]\d{5}$/", $str); } function is_idcard($str){ //检验身份证 return preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $str); } function is_chinese($str){ 检验是否是中文 return ereg("^[".chr(0xa1)."-".chr(0xff)."]+$",$str); } function is_english($str){ //检验是否是英文 return preg_match("/^[A-Za-z]+$/", $str); } function is_mobile($str){ //检验是否是手机 return preg_match("/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/", $str); } function is_phone($str){ //建云那是否是电话 return preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/", $str); } function is_safe($str){ return (preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|. {0,5})$|\s/", $str) != 0); } }
$data = array_column($row, 'id');//id、排序的字段名, $row 带排序数组 array_multisort($data, SORT_DESC, $row);//SORT_DESC 倒序 SORT_ASC 升序
#927
<style> /*利用:after伪元素*/ .clearUl:after { content:""; display: block; clear: both; } #ffmmright li a:active:before { content: '[ '; }#ffmmright li a:active:after { content: ' ]'; }#ffmmright li a:active{font-size: 18px;} </style> <script> window.alert = function(name){ var iframe = document.createElement("IFRAME"); iframe.style.display="none"; iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); window.frames[0].window.alert(name); iframe.parentNode.removeChild(iframe); } //重写confirm方法,去掉地址显示 window.confirm = function(name){ var iframe = document.createElement("IFRAME"); iframe.style.display="none"; iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); var result = window.frames[0].window.confirm(name); iframe.parentNode.removeChild(iframe); return result; } var ua = navigator.userAgent.toLowerCase(); var isWeixin = ua.indexOf('micromessenger') != -1; var isAndroid = ua.indexOf('android') != -1; var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1); /*if (isWeixin) { alert('微信来源'); }else{ alert('非微信来源'); }*/ window.onload=function(){ document.body.addEventListener('touchstart', function () { //...空函数即可 }); } </script>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> <style type="text/css"> div { /*关键代码*/ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .btn-blue { display: block; height: 42px; line-height: 42px; text-align: center; border-radius: 4px; font-size: 18px; color: #FFFFFF; background-color: blue; } .btn-blue-on { background-color: red; } </style> </head> <body> <div class="btn-blue">按钮</div> <script type="text/javascript"> var btnBlue = document.querySelector(".btn-blue"); btnBlue.ontouchstart = function() { this.className = "btn-blue btn-blue-on" } btnBlue.ontouchend = function() { this.className = "btn-blue" } btnBlue.onclick = function(){ alert(123) } </script> </body> </html>
style=" color: #000000; cursor: pointer; right: 28px; position: absolute; top: 0px; display: inline-block;outline :none;-webkit-appearance:none;-webkit-tap-highlight-color: rgba(0, 0, 0, 0); "
window.onload=function(){ document.body.addEventListener('touchstart', function () { //...空函数即可 }); }
a:link { /* Essentially means a[href], or that the link actually goes somewhere */ color: blue; } a:visited { color: purple; } a:hover { color: green; } a:active { color: red; }
#928
#929
#930
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); echo"<br/>"; var_dump(json_decode($json, true)); ?>
object(stdClass)#1 (5) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) }
json_decode($json, true)
var_dump(json_decode($json, true));
array(5) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) }
#931
确定要清除编辑框内容吗?
该删除操作将不可恢复。
删除 取消
激活Windows
转到"设置"以激活Windows。
#913
#914
slice() 方法可从已有的数组中返回选定的元素。
语法
arrayObject.slice(start,end)
返回值
返回一个新的数组,包含从 start 到 end (不包括该元素)的 arrayObject 中的元素。
说明
请注意,该方法并不会修改数组,而是返回一个子数组。如果想删除数组中的一段元素,应该使用方法 Array.splice()。
提示和注释
注释:您可使用负值从数组的尾部选取元素。
注释:如果 end 未被规定,那么 slice() 方法会选取从 start 到数组结尾的所有元素。
#915
第3条里的 "$$" 函数谁能讲解下?
IE11 里是
function(n,t){return t?t.querySelectorAll.call(t,n):window.document.querySelectorAll.apply(window.document,arguments)}
Edge里面是未定义(Microsoft Edge 41.16296.0.0)
Chrome 里
ƒ $$(selector, [startNode]) { [Command Line API] }
FF 的文档写它是 Web 开发控制台的 helper command
<p style="line-height: 18px; font-size: 18px; font-family: times;"> Click "<i>Load samples</i>" to view and edit more JS samples.<br> <br> Labyrinth generated with JavaScript:<br><br> <script> for (var line=1; line<60; line++) { for(var i=1;i<29;i++) { var s = (Math.floor((Math.random()*2)%2)) ? "╱" : "╲"; document.write(s); } document.writeln("<br>"); } </script> </p><!doctype html> <html> <body> <canvas id="can" width="400" height="400" style="background: Black"></canvas> <script> var sn = [ 42, 41 ], dz = 43, fx = 1, n, ctx = document.getElementById("can").getContext("2d"); function draw(t, c) { ctx.fillStyle = c; ctx.fillRect(t % 20 * 20 + 1, ~~(t / 20) * 20 + 1, 18, 18); } document.onkeydown = function(e) { fx = sn[1] - sn[0] == (n = [ -1, -20, 1, 20 ][(e || event).keyCode - 37] || fx) ? fx : n }; !function() { sn.unshift(n = sn[0] + fx); if (sn.indexOf(n, 1) > 0 || n<0||n>399 || fx == 1 && n % 20 == 0 || fx == -1 && n % 20 == 19) return alert("GAME OVER"); draw(n, "Lime"); if (n == dz) { while (sn.indexOf(dz = ~~(Math.random() * 400)) >= 0); draw(dz, "Yellow"); } else draw(sn.pop(), "Black"); setTimeout(arguments.callee, 130); }(); </script> </body> </html>#916
let a = 1, b = 2; [a, b] = [b, a];(10)["toString"]() === "10" 写成 10..toString() === "10" 更显装逼~console.log( '1.0123'.replace(/\B(?=(\d{3})+(?!\d))/g, ',')) result: 1.0,123Math.random().toString(36).substring(2)Math.random()在我chrome控制台(版本 55.0.2883.87 m)
Math.random().toString(36).substring(2)//经测试23-26位都有可能
"7jz8ov7swm7ong7w77x9jdobt9"
为何和上面的有差异性呢?是我Chrome版本太低还是太高导致JS的版本不一致导致的?
正常算法不是这个么:
const find = (arr,x) => arr.filter(num=>num===x)[0]||null;[...'8'.repeat(6)]if(~"asdf".lastIndexOf("a")){ alert("exists"); }~ 是按位非, ~1 是 -2,这个地方是因为, if 里面的条件要经过两次处理,
ToBoolean(GetValue(exprRef))
其中 GetValue ,如果不是引用就直接返回原值,ToBoolean在处理Number时的规则是
The result is false if the argument is +0, −0, or NaN; otherwise the result is true.
所以你这个是在大部分时候是没有问题的
#917
window.onerror = function(m, f, l){ return true }#918
eg:!!0 === false#919
(23333333).toLocaleString('en-US')#920
如何读懂并写出装逼的函数式代码
js奇淫技巧1
从一行代码里面学点JavaScript
有哪些短小却令人惊叹的 JavaScript 代码?
aaencode - Encode any JavaScript program to Japanese style emoticons (^_^) 在线js表情符号转码加密混淆
#921
#922
#923
#924
#925
取消事件的默认动作。
在 touchend 中解除 touchmove 绑定
$("#id").on(' touchstart',function(){ $("#id").on('touchmove',function(event) { event.preventDefault(); }, false);})$("#id").on(' touchend',function(){ $("#id").unbind('touchmove');})用
$("body").bind("touchmove",function(event){event.preventDefault;//code});取消了body的拖动事件。
恢复这个拖动事件只要
$("body").unbind("touchmove");#926
function is_email($str){ //检验email return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str); } function is_url($str){ //检验网址 return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"]) *$/", $str); } function is_qq($str){ //检验qq return preg_match("/^[1-9]\d{4,8}$/", $str); } function is_zip($str){ //检验邮编 return preg_match("/^[1-9]\d{5}$/", $str); } function is_idcard($str){ //检验身份证 return preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $str); } function is_chinese($str){ 检验是否是中文 return ereg("^[".chr(0xa1)."-".chr(0xff)."]+$",$str); } function is_english($str){ //检验是否是英文 return preg_match("/^[A-Za-z]+$/", $str); } function is_mobile($str){ //检验是否是手机 return preg_match("/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/", $str); } function is_phone($str){ //建云那是否是电话 return preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/", $str); } function is_safe($str){ return (preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|. {0,5})$|\s/", $str) != 0); } }php 多维数组排序
*php版本5.5以上
$data = array_column($row, 'id');//id、排序的字段名, $row 带排序数组 array_multisort($data, SORT_DESC, $row);//SORT_DESC 倒序 SORT_ASC 升序#927
芳芳造型
<style> /*利用:after伪元素*/ .clearUl:after { content:""; display: block; clear: both; } #ffmmright li a:active:before { content: '[ '; }#ffmmright li a:active:after { content: ' ]'; }#ffmmright li a:active{font-size: 18px;} </style> <script> window.alert = function(name){ var iframe = document.createElement("IFRAME"); iframe.style.display="none"; iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); window.frames[0].window.alert(name); iframe.parentNode.removeChild(iframe); } //重写confirm方法,去掉地址显示 window.confirm = function(name){ var iframe = document.createElement("IFRAME"); iframe.style.display="none"; iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); var result = window.frames[0].window.confirm(name); iframe.parentNode.removeChild(iframe); return result; } var ua = navigator.userAgent.toLowerCase(); var isWeixin = ua.indexOf('micromessenger') != -1; var isAndroid = ua.indexOf('android') != -1; var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1); /*if (isWeixin) { alert('微信来源'); }else{ alert('非微信来源'); }*/ window.onload=function(){ document.body.addEventListener('touchstart', function () { //...空函数即可 }); } </script>html点击有阴影
去掉点击后面阴影区域方块决解方法css
今天偶然发现一件很奇怪的事儿。
在移动端,在我去掉css的伪类及其伪元素跟相关的js之后,
在我点击某块区域的时候,总有一个背景盖在上面,当初以为是Js搞得鬼,
后来发现却不以为然,原来是css的一个属性搞得鬼,希望可以帮到大家。
问题1:
如图所示,我所遇到的状况:
问题2:去掉点击区域的边框阴影效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> <style type="text/css"> div { /*关键代码*/ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .btn-blue { display: block; height: 42px; line-height: 42px; text-align: center; border-radius: 4px; font-size: 18px; color: #FFFFFF; background-color: blue; } .btn-blue-on { background-color: red; } </style> </head> <body> <div class="btn-blue">按钮</div> <script type="text/javascript"> var btnBlue = document.querySelector(".btn-blue"); btnBlue.ontouchstart = function() { this.className = "btn-blue btn-blue-on" } btnBlue.ontouchend = function() { this.className = "btn-blue" } btnBlue.onclick = function(){ alert(123) } </script> </body> </html>style=" color: #000000; cursor: pointer; right: 28px; position: absolute; top: 0px; display: inline-block;outline :none;-webkit-appearance:none;-webkit-tap-highlight-color: rgba(0, 0, 0, 0); "移动端:active伪类无效的解决方法
在iOS系统的移动设备中,需要在按钮元素或body/html上绑定一个touchstart事件才能激活:active状态。
window.onload=function(){ document.body.addEventListener('touchstart', function () { //...空函数即可 }); }a:link { /* Essentially means a[href], or that the link actually goes somewhere */ color: blue; } a:visited { color: purple; } a:hover { color: green; } a:active { color: red; }#928
html点击有阴影
去掉点击后面阴影区域方块决解方法css
今天偶然发现一件很奇怪的事儿。
在移动端,在我去掉css的伪类及其伪元素跟相关的js之后,
在我点击某块区域的时候,总有一个背景盖在上面,当初以为是Js搞得鬼,
后来发现却不以为然,原来是css的一个属性搞得鬼,希望可以帮到大家。
问题1:
如图所示,我所遇到的状况:
问题2:去掉点击区域的边框阴影效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> <style type="text/css"> div { /*关键代码*/ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .btn-blue { display: block; height: 42px; line-height: 42px; text-align: center; border-radius: 4px; font-size: 18px; color: #FFFFFF; background-color: blue; } .btn-blue-on { background-color: red; } </style> </head> <body> <div class="btn-blue">按钮</div> <script type="text/javascript"> var btnBlue = document.querySelector(".btn-blue"); btnBlue.ontouchstart = function() { this.className = "btn-blue btn-blue-on" } btnBlue.ontouchend = function() { this.className = "btn-blue" } btnBlue.onclick = function(){ alert(123) } </script> </body> </html>#929
我听到的版本是这样的: B成了A的领导, 让A重构之前B写的代码
#930
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); echo"<br/>"; var_dump(json_decode($json, true)); ?>数组$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';被json_decode()解码,转换回来的数据是对象,var_dump(json_decode($json))得到的是一个对象,如下:
object(stdClass)#1 (5) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) }那么,要怎么样才能把json数组转换为php格式的数组呢,采用以下方式:
json_decode($json, true)这样得到的数据就是php的数组了:
var_dump(json_decode($json, true));效果如下:
array(5) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) }#931