whrice
whrice
[demo](https://codepen.io/whrice/pen/MWWxOLW) ```js let ul = document.querySelector("#list"); let input = document.querySelector("#input"); let list = document.querySelectorAll("li"); ul.addEventListener("click", function(e) { for (var i = 0; i < list.length; i++) { if (list[i].classList.contains("selected")) {...
[link](https://codepen.io/whrice/pen/voYpeo) css ```css .item { margin: 0 0 10px 0; } .tag { display: inline-block; border: 1px solid#aeafaf; padding: 0 2px; } .type { color: #aeafaf; } .status { color:...
1 ``` encodeURI主要用于对整个URI进行编码,对于URI的特殊字符,会忽略对其的编码, encodeURIComponent主要用于对URI后的参数进行编码,不会忽略对特殊字符的编码。 ``` 2 ```js Object.keys(object1).map(function(index){ str.push(index+'='+encodeURIComponent(object1[index])) }); var str1=str.join('&') console.log(str1) ``` 3 ```js location.search ``` 4,5 ```js //zxx: 有bug 例如?a=1&b=2&url=a.html?b=1,b=1应该忽略 var str2 = decodeURIComponent(location.search).slice(1).split('&'); var obj =...
1 ```js var dialog=document.createElement('dialog'); document.body.append(dialog); ``` 2 ```js dialog.open=true; ``` 3 ```js var btn=document.createElement('button'); btn.textContent="close"; dialog.appendChild(btn); btn.addEventListener('click',function(){ this.parentNode.close(); }) ``` 4 ```js if(dialog.open){ dialog.open=false; } dialog.showModal() ``` 5 ```js 想法是showModal的层级是最高的,把最后出现的dialog设置为showModal,那么如何找出最后出现的dialog...
```js var arr = [{ skin: 1 }, { skin: 2 }, { skin: 3 }, { skin: 4 }, { skin: 5 }, { skin: 6 }, { skin:...
```css body{ padding:20px; } .icon-delete{ text-decoration: none; position: relative; } .css-tips::before{ position: absolute; content: attr(data-title); border-radius: 6px; border: 1px solid black; text-align:center; width:42px; height:25px; color:white; background-color: black; top:-42px; left:-6px; font-size:10px;...
1. ```js var textarea=document.querySelector('textarea') ``` 2. ```js textarea.setAttribute('rows',5) ``` 3. ```js console.log(window.getComputedStyle(textarea).height) ``` 4. ```js function setHeight(textarea){ var lineHeight=window.getComputedStyle(textarea).lineHeight var fontSize=window.getComputedStyle(textarea).fontSize.slice(0,-2) console.log(fontSize) console.log(lineHeight) if(lineHeight=='normal'){ lineHeight=fontSize*1.2;//设置默认行高属性1.2 } else{ lineHeight=lineHeight.slice(0,-2) } textarea.style.height=lineHeight*textarea.rows+'px';...
```js //1 function formatTitleOmit(title) { let len = title.length; return len > 15 ? title.substr(0, 6) + "..." + title.substr(len - 6, 6) : title; } //2 function formatFileOmit(filename) {...
```js //zxx: 1,3,4测试没通过,题1首字母不大写,还有缩进扣1分 //toCamelCase function toCamelCase(str) { return str .split("-") .map(ele => { return ele.slice(0, 1).toUpperCase() + ele.slice(1).toLowerCase(); }) .join(""); } console.log(toCamelCase("abc-def-ghi")); //toDashJoin function toDashJoin(str) { return str.replace(/[A-Z]/g, ele =>...
[demo](https://codepen.io/whrice/pen/LYPjNjp) ```css ul,li,a { margin: 0; padding: 0; } ul { list-style: none; } a { text-decoration: none; color: #0077cc; } .content { width: 300px; font-size: 12px; background: #fff8dc; border:...