Wing Meng

Results 75 comments of Wing Meng

**[> 在线 DEMO 移动端长按网页会弹出默认菜单,这个菜单会打断长按滑动操作,被这个问题折磨了好久,后来终于找到根因解决了。[避坑指南](https://codepen.io/wingmeng/pen/PvymKN) ```js let boxNums = 20; new Box(boxNums); // 调用 ``` ```js class Box { constructor(nums = 0) { this.nums = isNaN(nums) ? 0 : Math.floor(nums); //...

#### ES6 方式 ```js const result = [...new Set(data.map(item => item.value))]; ``` #### ES5 方式 ```js var result = data.reduce(function(arr, item) { return !~arr.indexOf(item.value) ? arr.concat(item.value) : arr }, []);...

写之前翻看了下 Chrome 原生 `` 的 shadow DOM,有所启发。 [> 在线 DEMO i { position: relative; left: calc(.3125em * 2); } .audio-controls-button-volume-icon > i::before { content: ""; position: absolute; width: .7em; height:...

[> 在线 Demo

#### 第 1 题: ```js document.querySelectorAll('[type=radio]:required'); ``` #### 第 2 题: ```js // 处于禁用状态的 fieldset 下的 radio 也包含在内 document.querySelectorAll('[type=radio]:disabled'); ``` #### 第 3 题: ```js document.querySelectorAll('[type=radio]:checked'); ``` #### 第 4...

[> 在线 DEMO { this.val(value); } } } // 渲染 DOM render() { const container = document.querySelector(this.el); const slider = document.createElement('div'); this.slider = slider; // 有缺省值则赋值 if (this.value) { this.val(this.value);...

#### 第 1 题: ```js function colorPad(hex) { const reg = /^#?([0-9a-f]{1,3}|[0-9a-f]{6})$/i; let result = '#' + '0'.repeat(6); if (reg.test(hex)) { result = hex.replace(reg, (_, $1) => { $1 =...

没有什么字符串处理是用一个正则表达式解决不了的,如果有,那就用两个,事实上我用了四个。 [DEMO 更精彩](https://codepen.io/wingmeng/pen/EJVRWo) (已封装,并提供测试用例) ---- #### 第 1 题 > 这是送分题吗? ``` js content.length > 140; ``` #### 第 2 题 > 使用正则将所有连续空格、换行替换为1个 ``` js content.trim() // 移除两端空格 .replace(/[\r\n]+/g, '\n')...

[> 在线 Demo

直接使用强大的 Grid 布局,妥妥的。[> 在线 DEMO