前言
我是歌谣 放弃很容易 但是坚持一定很酷 微信公众号关注前端小歌谣带你进入前端巅峰交流群 今天继续对前端知识的小结
如何截取字符串
| <!DOCTYPE html> |
| <html lang="en"> |
| |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>substr</title> |
| </head> |
| |
| <body> |
| <script> |
| |
| |
| var str = "abcdefghij"; |
| |
| console.log("(1,2): " + str.substr(1, 2)); |
| |
| console.log("(-3,2): " + str.substr(-3, 2)); |
| console.log("(-3): " + str.substr(-3)); |
| console.log("(1): " + str.substr(1)); |
| console.log("(-20, 2): " + str.substr(-20, 2)); |
| console.log("(20, 2): " + str.substr(20, 2)); |
| </script> |
| </body> |
| |
| </html> |
如何用javascript获取所有的checkbox值220422
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <title>js</title> |
| </head> |
| |
| <script language="javascript"> |
| function aa() { |
| var r = document.getElementsByName('r') |
| |
| for (var i = 0; i < r.length; i++) { |
| if (r[i].checked) { |
| console.log(r[i].value + ',' + r[i].nextSibling.nodeValue) |
| } |
| } |
| } |
| </script> |
| |
| <body> |
| <form name="form1" method="post" action=""> |
| <input type="checkbox" name="r" value="1" />a<br /> |
| <input type="checkbox" name="r" value="2" />b<br /> |
| <input type="checkbox" name="r" value="3" />c<br /> |
| <input type="checkbox" name="r" value="4" />d<br /> |
| <input type="checkbox" name="r" value="5" />e<br /> |
| <input type="checkbox" name="r" value="6" />f<br /> |
| <input type="checkbox" name="r" value="7" />g<br /> |
| <input type="checkbox" name="r" value="8" />h<br /> |
| <input type="checkbox" name="r" value="9" />i<br /> |
| <input type="checkbox" name="r" value="10" />j<br /> |
| <br /> |
| <input type="button" onclick="aa()" value="button" /> |
| </form> |
| </body> |
| </html> |
如果ul下面有1000个li
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Document</title> |
| </head> |
| <body> |
| <script> |
| window.onload = function(){ |
| var ul=document.getElementById("ul") |
| ul.onclick = function(e){ |
| e=window.event?window.event:e; |
| var who=e.target?e.target:e.srcElement; |
| console.log(who.innerHtml) |
| } |
| } |
| </script> |
| </body> |
| </html> |
字符串反转
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Document</title> |
| </head> |
| <body> |
| <script> |
| |
| function myreserve(arr){ |
| |
| for(var i=0;i<arr.length/2;i++){ |
| var temp=arr[i] |
| arr[i]=arr[arr.length-i-1] |
| arr[arr.length-i-1]=temp |
| } |
| return arr |
| } |
| console.log(myreserve(["1","2","3","4","5"])) |
| |
| </script> |
| </body> |
| </html> |
宏任务和微任务
| <!DOCTYPE html> |
| <html lang="en"> |
| |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>宏任务和微任务</title> |
| </head> |
| |
| <body> |
| <script> |
| console.log(100) |
| setTimeout(() => { |
| console.log(200) |
| }) |
| Promise.resolve().then(() => { |
| console.log(300) |
| }) |
| console.log(400) |
| |
| |
| </script> |
| </body> |
| |
| </html> |
实现一个删除字符串前后空格的方法
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Document</title> |
| </head> |
| <body> |
| <script> |
| |
| String.prototype.deletePlace=function(){ |
| var str=this |
| while(str[0]===" "){ |
| str.substring(1) |
| } |
| while(str[str.length-1]===" "){ |
| str.substring(0,str.length-1) |
| } |
| return str |
| } |
| |
| |
| </script> |
| </body> |
| </html> |
寄生式继承
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>寄生式继承</title> |
| </head> |
| <body> |
| <script> |
| function object(obj) { |
| function F() {} |
| F.prototype = obj |
| return new F() |
| } |
| |
| function createAnother(original) { |
| var clone = object(original) |
| clone.sayHi = function () { |
| |
| console.log('我是歌谣') |
| } |
| return clone |
| } |
| |
| var person = { |
| name: 'Nicholas', |
| friends: ['Shelby', 'Court', 'Van'], |
| } |
| |
| var anotherPerson = createAnother(person) |
| anotherPerson.sayHi() |
| |
| </script> |
| </body> |
| </html> |
寄生组合式继承
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>寄生组合式继承</title> |
| </head> |
| <body> |
| |
| |
| <script> |
| function inheritPrototype(Son, Father) { |
| var prototype = Object.create(Father.prototype) |
| prototype.constructor = Son |
| Son.prototype = prototype |
| } |
| 0 |
| |
| function Father(name) { |
| this.name = name |
| this.colors = ['red', 'blue', 'green'] |
| } |
| Father.prototype.sayName = function () { |
| console.log(this.name) |
| } |
| |
| |
| function Son(name, age) { |
| Father.call(this, name) |
| this.age = age |
| } |
| |
| |
| inheritPrototype(Son, Father) |
| |
| |
| Son.prototype.sayAge = function () { |
| console.log(this.age) |
| } |
| var instance1 = new Son('xyc', 23) |
| var instance2 = new Son('lxy', 23) |
| |
| instance1.colors.push('2') |
| console.log(instance1) |
| instance1.colors.push('3') |
| console.log(instance1) |
| </script> |
| </body> |
| </html> |
总结
我是歌谣 最好的种树是十年前 其次是现在 加油 歌谣
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!